Https://app.dataquest.io/m/54/web-scraping/4/using-find-all

https://app.dataquest.io/m/54/web-scraping/4/using-find-all

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”)

Could you please explain what does [0] in the body[0] mean? “First Index”? I think you’d better add the explanation on the tutorial, thank you.

1 Like

Here it is probably made this way, so that we can understand logic how it works.

parser = BeautifulSoup(content, ‘html.parser’) extracts all html tags from the response, sent to us by server.

With this command body = parser.find_all(“body”) we are finding all <body> statement occurrences in the parser object. Looks a little artificial since according to W3C HTML specification there could be only one body statement in HTML doc. Nevertheless, it gives us understanding on how the parsing logic works.

And here we come to the answer on your question…

With p = body[0].find_all(“p”) we take FIRST occurrence, i.e. body[0] from all occurrences and in this first one we are finding all "p" tags, i.e. paragraphs.

Hope this helps a bit.

Thank you for the reply.
So we are using Index**[0]**, showing that is actually a list?