Screen Link:
https://app.dataquest.io/m/54/web-scraping/4/using-find-all
My Code:
title = parser.find_all('title')
title_text = head[0].text
In the code above, I used the parser to find title
directly, and it works, which bring my question about the sample code in this lesson:
parser = BeautifulSoup(content, 'html.parser')
# Get a list of all occurrences of the body tag in the element.
body = parser.find_all("body")
# Get the paragraph tag.
p = body[0].find_all("p")
# Get the text.
print(p[0].text)
The bit of code below seems unnecessary? Is there any particular reason that the instruction code contains this bit?
# Get a list of all occurrences of the body tag in the element.
body = parser.find_all("body")