[英]Empty response after submit a form with (requests) python package
我正在嘗試使用(請求)模塊提交表單。
這是我要提交的表格:
<form method="POST" enctype="multipart/form-data" action="/cgi-bin/claws72.pl">
<input type="hidden" name="email" value="a.nobody@here.ac.uk"><br>
<br>
Select tagset:
<input type="radio" name="tagset" value="c5" checked=""> C5
<input type="radio" name="tagset" value="c7"> C7
<br><br>
Select output style:
<input type="radio" name="style" value="horiz" checked=""> Horizontal
<input type="radio" name="style" value="vert"> Vertical
<input type="radio" name="style" value="xml"> Pseudo-XML
<br><br>
<textarea name="text" rows="10" cols="50" wrap="virtual">Type (or paste) your text to be tagged into this box.
</textarea>
<br>
<input type="SUBMIT" value="Tag text now">
<input type="reset" value="Reset form">
</form>
這是包含以下表格的網站: http : //ucrel.lancs.ac.uk/claws/trial.html
這是我的代碼:
import requests
data = {'email' : 'a.nobody@here.ac.uk',
'tagset':'c7',
'style' : 'xml',
'text' : 'TEST' }
r = requests.post('http://ucrel.lancs.ac.uk/cgi-bin/claws72.pl', data=data)
print(r.text) #0 words tagged (Why? it should tag the (TEST) word)
print(r.ok) #True
我在自己的網站表單中使用了相同的代碼,並且可以正常工作,但是在這里無法弄清楚為什么不這樣做! 您是否認為網站本身阻止了此類請求?
謝謝
如果您使用Firebug
或其他類似工具檢查請求數據,則會發現請求數據實際上是以下格式:
-----------------------------41184676334
Content-Disposition: form-data; name="email"
a.nobody@here.ac.uk
-----------------------------41184676334
Content-Disposition: form-data; name="tagset"
c7
-----------------------------41184676334
Content-Disposition: form-data; name="style"
xml
-----------------------------41184676334
Content-Disposition: form-data; name="text"
TEST
-----------------------------41184676334--
嘗試以這種方式格式化數據,然后再試一次。 另外,最好傳遞其他請求標頭字段(例如Accept-Encoding
, Content-Type
...)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.