'str' Object Has No Attribute 'p' Using Beautifulsoup
I have been following a tutorial on using BeautifulSoup, however when I try to read the title or even paragraphs (using soup.p) I get an error saying, 'Traceback (most recent call
Solution 1:
Quoting Beautiful Soup Documentation
The prettify() method will turn a Beautiful Soup parse tree into a nicely formatted Unicode string, with each HTML/XML tag on its own line.
You set an string to soup
var here: soup = soup.prettify()
. Of course a string has not p
property, then crashes.
To find all p
s:
...
page = response.read()
soup = BeautifulSoup(page, "html5lib")
for paragraph in soup.find_all('p'):
do_something_with(paragraph)
Post a Comment for "'str' Object Has No Attribute 'p' Using Beautifulsoup"