【发布时间】:2013-11-12 16:12:43
【问题描述】:
我正在尝试刮取以下地区的基金价格:
http://www.prudential.com.hk/PruServlet?module=fund&purpose=searchHistFund&fundCd=JAS_U
但是table中各行的class属性不同,有“class”:“fundPriceCell1”和“fundPriceCell2”:
<tr>
<td align="center" class="fundPriceCell1">08/11/2013</td><td align="center" class="fundPriceCell1">118.2500</td><td align="center" class="fundPriceCell1">118.2500</td>
</tr>
<tr>
<td align="center" class="fundPriceCell2">07/11/2013</td><td align="center" class="fundPriceCell2">118.9800</td><td align="center" class="fundPriceCell2">118.9800</td>
</tr>
如何刮桌子?这是错误的,但如何解决?
import pandas as pd
import requests
url = 'http://www.prudential.com.hk/PruServlet?module=fund&purpose=searchHistFund&fundCd=JAS_U'
tables = pd.read_html(requests.get(url).text, attrs={"class":"fundPriceCell1"})
【问题讨论】:
-
如果你的后端 html 解析器是 beutifulsoup,我猜你可以传递一个编译的正则表达式作为你的 attrs 字典中 'class' 元素的值
-
这是一个属性字典,我可以通过它来识别 HTML 中的表格。如何传递已编译的正则表达式?
标签: python-2.7 pandas python-requests