Matt
Matt

Reputation: 3557

Mechanize with multiple pages

search_1=raw_input('search criteria 1? ')
search_2=raw_input('search criteria 2? ')

br = mechanize.Browser()
br.open('website')
br.select_form(nr=0)
br['-c']=search_1
br['-c.rs']=search_2
br.set_handle_robots(False)
response=br.submit()
print response.read()

I run this mechanize script on one page, then the website will lead me to another page automatically wherein I need to run another mechanize script. My problem is that I don't know how to link them. How do you go about doing this nicely? Thanks.

Upvotes: 0

Views: 1226

Answers (1)

4d4c
4d4c

Reputation: 8159

There is no way to submit and to stay on the same page with all forms filled.

Instead why not create second instance of the mechanize browser and work in both simultaneously? For example:

from mechanize import Browser

br0 = Browser()
br1 = Browser()

br0.open('http://www.example.com/')
br1.open('http://www.example.com/')

Or another option is to use back() after submition, but you still will have to refill the form. For example:

from mechanize import Browser

br = Browser()

r = br.open('http://www.example.com/')
r = br.open('http://www.google.com/')
r = br.back()

print r.read()

Upvotes: 1

Related Questions