Skip to main content

Section 14.12 Code debugging activityCode debugging activity

Every week, a new cat or dog is the Ann Arbor’s 107one Pet-of-the-Week. The code below is supposed to get the pet of the week webpage, scrape the text of the title shown in the picture, and print it.
Figure 14.12.1. The pet of the week from August 22, 2020 is Chester.
However, it doesn’t work! Instead of printing the title text, it prints nothing.
Can you fix it? Try to fix the buggy code below. Run the code to save your progress.

Activity 14.12.1.

Fix the code below:
#Get the webpage
# Load libraries for web scraping
from bs4 import BeautifulSoup
import requests
# Get a soup from a URL
url = 'https://www.hshv.org/petsoftheweek/'
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html.parser')

#Get info from one tag
# Get first tag of a certain type from the soup
tag = soup.find('a', class_='pt-cv-none cvplbd')
# Get info from tag
info = tag.get('href')

#Do something with the info
# Print the info
print(info)
You have attempted of activities on this page.