BeautifulSoup hangs when using find

Viewed 1438

I have a problem with the bs4 package.

I have a html document, like this one:

data = """<html><head></head><body>
<p> this is tab </p>
<img src="image.jpg">
</body></html>
"""

This is my code:

from bs4 import BeautifulSoup
soup = BeautifulSoup(data, 'html5lib')
soup.find_all("a")

When I run it, bs4 is still in a loop and doesn't return anything, maybe because in some HTML data the tag a doesn't exist.

Many thanks.
1. Yes, above example working correctly.
2. But, in my case. data is a variable with multi lines html string

from bs4 import BeautifulSoup
data = open("file.htm").read()
soup = BeautifulSoup(data, 'html5lib')
soup.find_all("a")

3. Please test with my file: file.htm
4. I'm using beautifulsoup4==4.4.1. Python 3.5.1
5. Thanks again.

2 Answers
Related