[英]I don't get the complete table of an html with read_html
我试图使用 Panda 从 web 页面上的表格中获取信息,但它并没有向我提供所有信息和其他方式,我也不能。
import pandas as pd
calls_df = pd.read_html("https://google.com/covid19-map/?hl=es-419", index_col=1,
attrs={"class":"SAGQRd"})
df = pd.DataFrame(calls_df)
print(calls_df)
我用其他链接尝试了代码,如果他们从表格中获取信息,我的错误是什么?
pandas could probably not be the best way to get html data, try exploring the BeautifulSoup Module from: https://www.crummy.com/software/BeautifulSoup/bs4/doc/
要将 html 加载到 df 中,请尝试:
`import pandas as pd
from bs4 import BeautifulSoup
soup = BeautifulSoup(html, "html.parser")
table = soup.find('table', attrs={'class':'subs noBorders evenRows'})
table_rows = table.find_all('tr')`
`res = []
for tr in table_rows:
td = tr.find_all('td')
row = [tr.text.strip() for tr in td if tr.text.strip()]
if row:
res.append(row)
df = pd.DataFrame(res, columns=["Year", "Mintage", "Quality", "Price"])
print(df)`
嘿,
我刚刚通过 jupyter 检查了你的代码,它对我有用。 你也在使用 jupyter 吗? 可能是缓存有点满了:D重启你的IDE,或者电脑
我的设置:
Python 3.7.4
名称:pandas 版本:0.25.1
名称:jupyter 版本:1.0.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.