I don't know if this question has been asked before, but I couldn't find anything that could help solve my problem (hopefully I didn't misunderstand anything). I'm learning Python at the moment, using Python 3.5 with IPython, and I ran into some trouble using BeautifulSoup. As shown below,
import bs4
exampleFile = open('example.html')
exampleFile.read()
>>> '<html><head><title>The Website Title</title></head>\n<body>\n<p>Download my <strong>Python</strong> book from <a href=“http://inventwithpython.com”>my website</a>.</p>\n<p class=“slogan”>Learn Python the easy way!</p>\n<p>By <span id=“author”>Al Sweigart</span></p>\n</body></html>'
exampleSoup = bs4.BeautifulSoup(exampleFile.read(), 'html.parser')
exampleFile.read()
>>> ''
elems = exampleSoup.select('#author')
print(elems)
>>> []
I'm able to open and read example.html, but after I use BeautifulSoup, when I try to read the file again, it returns an empty string. I'm unable to define elems because of this.
I'm trying to understand why this is happening, but I couldn't figure it out so I decided to post a question.
Thanks in advance!