14.12. Code 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.
![The pet of the week from August 22, 2020 is Chester.](../_images/pet_of_the_week.png)
However, it doesn’t work! Instead of printing the title text, it prints nothing.
Can you fix it? Here is the buggy code:
#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)
Try to fix the buggy code below. Run the code to save your progress.
-
In solving the preceding problem I invested:
- 1. Very, very low mental effort
- 2. Very low mental effort
- 3. Low mental effort
- 4. Rather low mental effort
- 5. Neither low nor high mental effort
- 6. Rather high mental effort
- 7. High mental effort
- 8. Very high mental effort
- 9. Very, very high mental effort
You have attempted of activities on this page