按下按钮后,如何收集网页上显示的数据?
http://www.etf.com/etfanalytics/etf-fund-flows-tool
如果您在此网站中输入日期,然后单击提交,它将创建一个包含前十大ETF流入表的新页面。
我是Web服务和编程的初学者,但是我知道python和常规编程。任何指针如何做到这一点表示赞赏。
我需要按按钮后显示的数据才能进行研究。
一旦我能够获取特定日期范围内的数据,就可以对其进行编程,使其能够每天自动获取每日或每周的数据。谢谢。
最佳答案
此页面有两个表单输入。查看页面源以确定输入名称,然后使用requests library to post the form:
import requests
response = requests.post(
"http://www.etf.com/etfanalytics/etf-fund-flows-tool",
data={"startDate[date]":"2017-05-01","endDate[date]":"2017-06-01"})
print(reponse.text)
现在,您将HTML设为
response.text
,并且需要对其进行解析。我建议这样做,代码看起来像这样:from lxml import html
tree = html.fromstring(response.text)
top_creations_symbol_list = tree.xpath('//xpath/to/creation/symbols')
top_redemptions_symbol_list = tree.xpath('//xpath/to/redemption/symbols')
您最终将在两个列表中找到符号。