如何在Python中发送POST请求?
你好,我现在坐在一辆有Wifi的灰狗巴士上,想把第二个设备连接到网络上。但是我需要先在屏幕上接受一个合同,而这个设备没有浏览器。要接受合同,需要填写下面的表单。这个设备没有CURL,但有所有标准的Python 2.6库。
<form method="POST" name="wifi" id="wifi" action="http://192.168.100.1:5280/">
<input type="image" name="mode_login" value="Agree" src="btn_accept.gif" />
<input type="hidden" name="redirect" value="http://stackoverflow.com/">
</form>
我该怎么写一个简单的Python脚本来接受这个合同呢?
1 个回答
2
我觉得这个方法应该能解决问题:
import urllib
data = urllib.urlencode({"mode_login":"Agree","redirect":"http://stackoverflow.com"})
result = urllib.urlopen("http://192.168.100.1:5280/",data).read()
print result