如何正确抓取python网站表?

时间:2021-03-04 14:48:42

标签: python pandas

我正在尝试使用 python 抓取一些数据,但出现以下错误:

rows = table.find_all('tr')
AttributeError: 'NoneType' object has no attribute 'find_all'

我尝试了其他一些带有表格的网站,并且它工作得很好..有人可以帮我吗?

我的代码:

import pandas as pd
import requests
from bs4 import BeautifulSoup

url = 'https://www.cointobuy.io'

r = requests.get(url)
html = r.text

soup = BeautifulSoup(html)
table = soup.find('table', {"class": "t-chart"})
rows = table.find_all('tr')
data = []
for row in rows[1:]:
cols = row.find_all('td')
cols = [ele.text.strip() for ele in cols]
data.append([ele for ele in cols if ele])

result = pd.DataFrame(data, columns=['#', 'Name', 'Current Price', 'Safety Rank', 'Potential Profit', 'Potential Price'])

print(result)

当表格中的某些内容发生变化时,我还想向自己发送(邮件)任何更新。有什么想法吗?

0 个答案:

没有答案