2
我怎樣才能湊基金的價格:如何使用Pandas read_html和請求庫來讀取表格?
http://www.prudential.com.hk/PruServlet?module=fund&purpose=searchHistFund&fundCd=JAS_U
這是錯誤的,但我怎麼修改:
import pandas as pd
import requests
import re
url = 'http://www.prudential.com.hk/PruServlet?module=fund&purpose=searchHistFund&fundCd=JAS_U'
tables = pd.read_html(requests.get(url).text, attrs={"class":re.compile("fundPriceCell\d+")})
這是一個相當凌亂的HTML,我想你會需要探索XML樹搶正確的值。 attr類應該放在桌子上而不是單元格(我認爲)... –
對不起。這是否意味着我必須導入BeautifulSoup4?任何建議? –
免責聲明:我可能是錯的,可能有一個簡單的方法來獲取read_html來抓住這個。如果沒有,我想像這樣:http://stackoverflow.com/a/16993660/1240268,但它有點雜亂/尷尬。 –