开发者

how to find the POST or GET variables posted by mechanize (python)

i'm using mechanize to submit a form like this...

import mechanize

br = mechanize.Browser()
br.open('http://stackoverflow.com')
br.select_form(nr=0)
br['q'] = "test"
br.set_handle_robots(False)

response = br.submit()

print response.info()
print response.read()

using firebug i can see that the actual variables pos开发者_开发百科ted are:

q test

how can i retrieve these programatically using my python script?

please note i'm not actually scraping SO - just using it as an example!

also, i know in this case the posted variables are obvious, since there's only the one i specified - often this is not the case!

thanks :)


You can enable debug mode in mechanize by putting this:

import mechanize

br = mechanize.Browser()
br.set_debug_http(True)
... 

Hope this can help :)


print br.form.get_value('q')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜