python请求帖子不提交

时间:2016-08-25 11:31:18

标签: python

我有一个request.post的问题,而不是返回带有结果的html代码我得到了起始方的html代码。

import requests
def test(pdb):
   URL = "http://capture.caltech.edu/"
   r = requests.post(URL,files={"upfile": open( pdb)})
   content=r.text
   print(content)
   print(r.headers)



def main():
  test("Model.pdb")

难道我必须定义我想要使用哪种postmethod?因为html文件中有两个。如果是这种情况我该怎么做?(我想使用第二个。)

<FORM ACTION="result.cgi" METHOD=POST>
<form action="capture_ul.cgi" method="post" enctype="multipart/form-data">

我知道这里有类似的问题,但那里的答案没有帮助,因为错误是使用了params而不是文件,这应该不是问题。

提前致谢。

1 个答案:

答案 0 :(得分:2)

1 - 您发布的网址错误,应为http://capture.caltech.edu/capture_ul.cgi

2 - 必须发送一个隐藏字段(name='note')(空字符串的值就足够了)。

...
def test(pdb):
   URL = "http://capture.caltech.edu/capture_ul.cgi"
   r = requests.post(URL,files={"upfile": open(pdb)}, data={'note': ''})
   content=r.text
   print(content)
   print(r.headers)
...
相关问题