Python使用机械化提交帖子数据

Python使用机械化提交帖子数据

问题描述:

我必须提交到服务器的网址如下:

The url that i have to submit to the server looks like this:

www.mysite.com/manager.php?checkbox%5B%5D=5&checkbox%5B%5D=4&checkbox%5B%5D=57&self=19&submit=Go%21

我这样张贴信息:

data = {'checkbox%5B%5D': '4', ....and so on... 'self': '19', 'submit': 'Go%21'}

我将其编码:

data = urllib.urlencode(orbs)

这就是我的运行方式:

resp = mechanize.Request('http://mysite.com/manager.php', data)
cj.add_cookie_header(resp)
res = mechanize.urlopen(resp)
print res.read()

错误提示:我没有选择任何项目. 我有嵌套表格,该如何不使用br.select_form(nr = 0)来正确处理呢? 谢谢.

And the error says: That i didnt select any item. How can I do it right without using br.select_form(nr=0) because I have nested forms? Thanks.

您对复选框字段名称进行了双重编码;您应该使用checkbox[]而不是checkbox%5B%5D.另外,由于该键名已被重用,因此您可能无法使用字典来收集参数.

You double-encoded the checkbox field names; you should use checkbox[] instead of checkbox%5B%5D. Also, because that key name is reused, you probably can't use a dictionary to gather up the arguments.