通过传递自定义日期输入来解析html内容 [英] parse html content by passing custom date input
本文介绍了通过传递自定义日期输入来解析html内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从此处解析数据.在网页上,我可以通过选择所需的日期来获取例如昨天的数据.如何解析以获取相同的数据(即昨天)?例如,传递自定义日期以获取该日期的数据.
I am parsing data from here. On the webpage I can get data for example yesterday by selecting the desired date. How can I parse to get the same data (ie. yesterday)? Like, pass custom dates to get data for that date.
推荐答案
您可以使用Selenium
或使用网站的ajax api.
这是后者的一个示例:
You can either use Selenium
or use the site's ajax api.
Here is an example of the latter:
def get_by_date(date):
url = 'https://markets.ft.com/data/world/ajax/getnextecoevents?startDate=' + date
r = requests.get(url)
return r.json()['html']
date
的格式应为yyyy-mm-dd,例如:"2017-07-20"
date
should be formatted as yyyy-mm-dd, eg: "2017-07-20"
使用上述功能和bs4
刮擦表格内容:
Using the above function and bs4
to scrape the table contents:
html = get_by_date('2017-06-20')
soup = BeautifulSoup(html, 'html.parser')
data = [[td.text for td in tr.find_all('td')] for tr in soup.find('table').find_all('tr')]
这篇关于通过传递自定义日期输入来解析html内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文