我正在尝试从网页中获取一些数据,但是我一直收到错误消息。试图搜索谷歌,但我似乎找不到一个好的解决方案。
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'
您需要将表的类具有,而不仅仅是表,在您的情况下,它具有 cmc-table
table = soup.find('table', {'class': 'cmc-table'}
试试这个它得到表
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句