Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 尝试刮表时出错_Python_Json_Beautifulsoup - Fatal编程技术网

Python 尝试刮表时出错

Python 尝试刮表时出错,python,json,beautifulsoup,Python,Json,Beautifulsoup,我试图从网页上获取一些数据,但我不断地出错。尝试搜索谷歌,但我似乎找不到一个好的解决办法 url = "https://coinmarketcap.com/currencies/bitcoin/historical-data/" content = requests.get(url).content soup = BeautifulSoup(content,'html.parser') table = soup.find('table', {'class': 'table'}

我试图从网页上获取一些数据,但我不断地出错。尝试搜索谷歌,但我似乎找不到一个好的解决办法

url = "https://coinmarketcap.com/currencies/bitcoin/historical-data/"
content = requests.get(url).content
soup = BeautifulSoup(content,'html.parser')
table = soup.find('table', {'class': 'table'})
print(table)


data = [[td.text.strip() for td in tr.findChildren('td')]
        for tr in table.findChildren('tr')]

输出:

Traceback (most recent call last):
  File "C:/Users/Ejer/PycharmProjects/pythonProject/stock_analysis.py", line 13, in <module>
    for tr in table.findChildren('tr')]
AttributeError: 'NoneType' object has no attribute 'findChildren'
回溯(最近一次呼叫最后一次):
文件“C:/Users/Ejer/PycharmProjects/pythonProject/stock_analysis.py”,第13行,在
对于表中的tr.findChildren('tr')]
AttributeError:“非类型”对象没有属性“findChildren”

嗯,我认为您使用的URL不正确。请检查一次并使用正确的表。

您需要将表的类设置为has,而不仅仅是table,在您的情况下,它具有
cmc table

table = soup.find('table', {'class': 'cmc-table'}

尝试此操作,它将获取表格

抱歉,我们找不到您的页面
此网页显示了您尝试获取的url的此部分。如果您打印表格,它将是
None
您没有要解析的html,对此表示抱歉。我刚刚更新了问题。这是正确的url。我仔细检查了一下