我的问题如下:我正在尝试编写一个贯穿机票网站订购流程的刮板。所以我想根据之前页面的结果抓取几页(我希望你明白我的意思)。我现在到目前为止:
import mechanize, urllib, urllib2
url = 'any url'
br = mechanize.Browser()
br.set_handle_robots(False)
br.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 5.2; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11')]
br.open(url)
response = br.response().read()
br.select_form(nr=1)
br.form.set_all_readonly(False)
## now I am reading out the variables of form(nr=1)
for control in br.form.controls:
if not control.name:
print " - (type) =", (control.type)
continue
print " - (name, type, value) =", (control.name, control.type, br[control.name])
## now I am modifying the variables
br['fromdate'] = '2012/11/03'
br['todate'] = '2012/11/07'
## now I am submitting the form and saving the output in the variable bookingsite
response = br.submit()
bookingsite = response.read()
这是我的问题:如何使用变量 bookingsite,它再次包含我要修改和提交的表单,就像普通 URL 一样?只需通过设置
br.open(bookingsite)
???还是有另一种修改和提交输出的方法(然后再次提交输出并接收新的输出页面)?