将 html table 转换为 pandas 数据帧

Converting html table to a pandas dataframe

我一直在尝试从网站导入 html table 并将其转换为 pandas DataFrame。这是我的代码:

import pandas as pd
table = pd.read_html("http://www.sharesansar.com/c/today-share-price.html")
dfs = pd.DataFrame(data = table)
print dfs 

它只是显示这个:

0       S.No                                     ...

但如果我这样做了;

for df in dfs:
    print df

输出table..

如何使用pd.Dataframe来抓取table?

HTML table 在给定的 url 上呈现 javascript。 pd.read_html() 不支持 javascript 呈现的页面。您可以像这样尝试 dryscrape

import pandas as pd
import dryscrape

s = dryscrape.Session()
s.visit("http://www.sharesansar.com/c/today-share-price.html")
df = pd.read_html(s.body())[5]
df.head()

输出: