我正在使用mechanize提交这样的表格......
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()
使用firebug我可以看到发布的实际变量是:
q test
如何使用我的python脚本以编程方式检索这些?
请注意我实际上并不是在刮它 - 只是以它为例!
另外,我知道在这种情况下发布的变量是显而易见的,因为只有我指定的那个 - 通常情况并非如此!
谢谢:)
答案 0 :(得分:2)
您可以通过以下方式在机械化中启用调试模式:
import mechanize
br = mechanize.Browser()
br.set_debug_http(True)
...
希望这有助于:)
答案 1 :(得分:1)
print br.form.get_value('q')