如何使用python中的pandas仅从具有两个 dataframe 的网页中选择第二个 dataframe ?

我试图仅在此url上使用第二个数据帧,但是我不知道如何指定仅获取一个数据帧.它打印出图表和表格的 dataframe ,但我要打印的只是表格.

`import pandas as pd  
 import urllib.request

page = pd.read_html('https://www.google.com/finance/historical?q=a&startdate=Jan%201%2C%202000&enddate=Feb%2028%2C%202017&num=200&ei=_nm3WKGHCIf7jAG74ar4Cw&start=200', header=0)

for df in page:
    print(df)`

最佳答案

您要查找的表具有类属性gf-table,将其传递给pd.read_html,则它将仅读取第二个表:

page = pd.read_html('https://www.google.com/finance/historical?q=a&startdate=Jan%201%2C%202000&enddate=Feb%2028%2C%202017&num=200&ei=_nm3WKGHCIf7jAG74ar4Cw&start=200', 
                    attrs = {'class': 'gf-table'},
                    header=0)
​
page

#             Date   Open   High    Low  Close   Volume
#0    May 12, 2016  42.59  42.94  42.42  42.73  2224506
#1    May 11, 2016  42.19  43.20  42.12  42.46  3325515
#2    May 10, 2016  41.50  42.00  41.35  42.00  2094305
#3     May 9, 2016  41.51  41.78  41.29  41.33  1741539
#4     May 6, 2016  40.86  41.62  40.72  41.43  1403476
#5     May 5, 2016  40.64  41.03  40.51  40.96  1083956
#...