說明:直接調用pands中的pd.read_html(url)函數,如果頁面中有表格,那麼表格數據會以DataFrame格式存儲下來。
比如我要獲取下面的數據:
調用代碼:
import pandas as pd
pd.set_option('display.width',1000)
pd.set_option('display.max_row',1000)
pd.set_option('display.max_column',1000)
html=pd.read_html('http://www.hbzwfw.gov.cn/art/2019/11/28/art_21290_7313.html')
print(html[1])
取出表格的數據是這樣的:
這樣就省去了用爬蟲爬去再取篩選td/tr標籤了,還是比較方便的。