Section14.6Plan 5: Get info from all tags of a certain type
To get information from the Cottage Inn locations page, we need to figure out which tags we should get from the soup, and what information we should get from the tags.
The name of this tag is βh3β. In-between the start and end tag (between the <h3> and </h3>) is the tagβs text. For this tag, the text is Ann Arbor Broadway St.
# Get all tags of a certain type from the soup
tags = soup.find_all('h3')
# Collect info from the tags
collect_info = []
for tag in tags:
# Get info from tag
info = tag.text
collect_info.append(info)
Right now, this code gets the text from all βh3β tags in the webpage. If you wanted to get the links from all the βaβ, class_=βheadlineβ tags in the webpage, which part(s) of the code below would you change?
# Get all tags of a certain type from the soup
tags = soup.find_all('h3')
# Collect info from the tags
collect_info = []
for tag in tags:
# Get info from tag
info = tag.text
collect_info.append(info)
# Get all tags of a certain type from the soup
tags = soup.find_all( _______ )
# Collect info from the tags
collect_info = []
for tag in tags:
# Get info from tag
info = tag. _______
collect_info.append(info)