python - 如何正确抓取 python 网站表?
问题描述
我试图使用 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)
当表格中的某些内容发生变化时,我还想向自己发送(邮件)任何更新。有什么想法吗?
解决方案
推荐阅读
- go - 使用 Go 从 csv 数据框的列创建文本文件
- php - php 5.3版本如何实现PHP Facebook登录?
- javascript - 如何将变量转换为特定类型以说服打字稿无处不在?
- python - Python 无法加载 .txt 文件
- flutter - 更改滑块高度
- python - 无法在 Python 中使用 Gdal 编写光栅。错误:dict' 对象没有属性 'shape'
- java - 线程“主”java.lang.ArrayIndexOutOfBoundsException 中的异常:2?偶尔工作得很好或有这样的问题
- r - fontfamily 在格子图中没有为 ylab 和 xlab 绘制相同的图
- c# - AddApiAuthorization 无隐式引用转换 ASP Core 3.0
- c++ - no operator "=" 匹配这些操作数,JUCE 窗口演示应用