Reputation: 151
I am new to webscraping and trying to get information from Google Trends website about the Average of keywords used.
Currently I am getting the error $AttributeError: 'NoneType' object has no attribute 'find_all'. I think that the error is because 'bar-chart-content' as a class may not exist as the name in HTML.
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
quote_page = 'https://trends.google.com/trends/explore?geo=US&q=pikachu,Cat'
page = requests.get(quote_page)
soup = BeautifulSoup(page.text, 'html.parser')
table = soup.find('div', {'class': 'bar-chart-content'}).find_all('td') #Gives the error: AttributeError: 'NoneType' object has no attribute 'find_all'
Please tell me to how to fix this issue and any suggestions on how to find the correct class name in the future for a website excluding inspect [if that is the issue] ?
EDIT: Based on MePsyDuck's answer, the class does not exist so how can find the correct name?
Upvotes: 0
Views: 2292
Reputation: 374
Just check if soup finds any <div>
before trying to find td
.
If there is no <div>
with your specified class, then the div
object will be None (which we can check easily).
Replace the last line in your code with:
div = soup.find('div', {'class': 'bar-chart-content'})
if div is not None:
table = div..find_all('td')
# Process futher
Upvotes: 1