我是新的网站搜索,并试图从谷歌趋势网站获得有关平均使用关键字的信息。在
当前我收到错误$AttributeError:“NoneType”对象没有“find\u all”属性。我认为错误是因为'bar chart content'作为一个类可能不存在于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'
请告诉我如何修复此问题,以及如何在将来为排除inspect的网站找到正确类名的任何建议[如果是这个问题]?在
编辑:根据MePsyDuck的回答,该类不存在,因此如何找到正确的名称?在
在尝试查找}对象将是None(我们可以很容易地检查)。在
td
之前,只需检查soup是否找到<div>
。 如果指定的类没有<div>
,那么{将代码中的最后一行替换为:
相关问题 更多 >
编程相关推荐