繁体   English   中英

为什么request.post对Clustal Omega服务没有响应?

[英]Why requests.post have no response with Clustal Omega service?

import requests
MSA_request=""">G1
MGCTLSAEDKAAVERSKMIDRNLREDGEKAAREVKLLLL
>G2
MGCTVSAEDKAAAERSKMIDKNLREDGEKAAREVKLLLL
>G3
MGCTLSAEERAALERSKAIEKNLKEDGISAAKDVKLLLL"""
q={"stype":"protein","sequence":MSA_request,"outfmt":"clustal"}
r=requests.post("http://www.ebi.ac.uk/Tools/msa/clustalo/",data=q)

这是我的脚本,我将此请求发送到网站,但结果似乎我什么也没做,Web服务未收到我的请求。 这种方法曾经与其他网站配合使用过,也许此页面带有弹出窗口以询问Cookie协议?

您所引用页面上的表单具有单独的URL,即

http://www.ebi.ac.uk/Tools/services/web_clustalo/toolform.ebi

您可以在浏览器中使用DOM检查器进行验证。 因此,为了处理requests ,您需要访问正确的页面

r=requests.post("http://www.ebi.ac.uk/Tools/services/web_clustalo/toolform.ebi",data=q)

这将使用您的输入数据提交作业,它不会直接返回结果。 要检查结果,有必要从先前的响应中提取作业ID,然后生成另一个请求(无数据)以

http://www.ebi.ac.uk/Tools/services/web_clustalo/toolresult.ebi?jobId=...

但是,您绝对应该检查此程序访问是否与该网站的TOS兼容...

这是一个例子:

from lxml import html
import requests
import sys
import time

MSA_request=""">G1
MGCTLSAEDKAAVERSKMIDRNLREDGEKAAREVKLLLL
>G2
MGCTVSAEDKAAAERSKMIDKNLREDGEKAAREVKLLLL
>G3
MGCTLSAEERAALERSKAIEKNLKEDGISAAKDVKLLLL"""
q={"stype":"protein","sequence":MSA_request,"outfmt":"clustal"}

r = requests.post("http://www.ebi.ac.uk/Tools/services/web_clustalo/toolform.ebi",data = q)
tree = html.fromstring(r.text)
title = tree.xpath('//title/text()')[0]

#check the status and get the job id
status, job_id = map(lambda s: s.strip(), title.split(':', 1))
if status != "Job running":
    sys.exit(1)

#it might take some time for the job to finish
time.sleep(10)

#download the results
r = requests.get("http://www.ebi.ac.uk/Tools/services/web_clustalo/toolresult.ebi?jobId=%s" % (job_id))

#prints the full response
#print(r.text)

#isolate the alignment block
tree = html.fromstring(r.text)
alignment = tree.xpath('//pre[@id="alignmentContent"]/text()')[0]
print(alignment)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM