Reputation:
so, i was making a covid map using web scraping, but i have never used it, anyways here is my python code
import requests
from bs4 import BeautifulSoup
page = requests.get('https://news.google.com/covid19/map?hl=en-US&gl=US&ceid=US%3Aen&mid=%2Fm%2F016zwt')
soup = BeautifulSoup(page.content, 'html.parser')
week = soup.find_all(class_='l3HOY')
print(week[7]).get_text()
but when i try to run it, it gives this error
print(week[7].find('td').get_text())
AttributeError: 'NoneType' object has no attribute 'get_text'
can anyone tell me how i can fix it?
Upvotes: 0
Views: 989
Reputation: 17408
import requests
from bs4 import BeautifulSoup
page = requests.get('https://news.google.com/covid19/map?hl=en-US&gl=US&ceid=US%3Aen&mid=%2Fm%2F016zwt')
soup = BeautifulSoup(page.content, 'html.parser')
week = soup.select(".l3HOY")
print(week[7].get_text())
Output: 15,964
Changes you have to make
get_text
method is on the week
element not on the print statementUpvotes: 1