python - BeautifulSoup returns an empty string? -


i don't know if question has been asked before, couldn't find solve problem (hopefully didn't misunderstand anything). i'm learning python @ moment, using python 3.5 ipython, , ran trouble using beautifulsoup. shown below,

import bs4 examplefile = open('example.html') examplefile.read() >>> '<html><head><title>the website title</title></head>\n<body>\n<p>download <strong>python</strong> book <a href=“http://inventwithpython.com”>my website</a>.</p>\n<p class=“slogan”>learn python 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 open , read example.html, after use beautifulsoup, when try read file again, returns empty string. i'm unable define elems because of this.

i'm trying understand why happening, couldn't figure out decided post question.

thanks in advance!

i believe issue having multiple calls read(). should use seek(0) rewind beginning of file before trying read again. here similar question.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -