2017-02-09 21 views
1

私はウェブサイトからhtmlテーブルをインポートし、パンダDataFrameに変換しようとしています。これは私のコードです:htmlテーブルをpandasデータフレームに変換する

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 

それは

がどのように私はテーブルをこすりするpd.Dataframeを使用することができます。..テーブルを出力しますか?

答えて

3

指定されたURLのHTMLテーブルが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() 

出力:

enter image description here

関連する問題