简体   繁体   中英

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 posted 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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM