使用请求浏览多个页面

Using requests to navigate through multiple pages

我正在尝试浏览以下网页:

http://www.regulomedb.org/

基本上,我在文本框中输入我的数据,然后单击提交。提交后,我要下载可用的文件。

截至目前,我有:

data = {'data': 'rs7881236'}
resp = requests.post('http://www.regulomedb.org/results', data)

当我查看resp的内容时,我能够得到下一页的HTML文本。但是,我需要做的是下载文件。我不确定在提交后如何导航。棘手的部分是我需要通过第一页提交我的数据。然后在到达第二页后,我需要以某种方式导航到下载 link,但我不确定如何使用已生成的响应对象来执行此操作。

您可能想要使用 RoboBrowser or Beautiful Soup to parse the values from the download form, and once you have those, you can make another POST request to http://www.regulomedb.org/download

这样的库

我在chrome中用了'inspect'发现其实是两次调用。搜索调用返回一种名称为 'sid' 的密钥,然后用于下载正确的文件。以下对我有用,只是测试你给出的一个例子:

import requests
import re

query = 'rs7881236'
d_format = 'full' #optionas are 'full', 'gff', or 'bed'


query_payload = {'data': query}
r = requests.post('http://www.regulomedb.org/results', query_payload)
val = re.findall('name="sid" value="(.*?)"', r.text)

file_payload = {'format':d_format,'sid':val}
f = requests.post('http://www.regulomedb.org/download', file_payload)
print(f.text)