2

I'm having a little difficulty trying to navigate a website past the login screen. I've done this using mechanize. However once I navigate past the login page I want to interact with the page, click attributes, etc. which mechanize cannot do. I also want to do this all "behind the curtain" so the browser window is invisible (trying not to use selenium).

Here is the code I use to login. What can I do past this to start interacting with the page

import mechanize

br = mechanize.Browser()
#get computer browser

br.set_handle_robots(False)
#what robots?

br.open("www.website.com")
#open website

br.select_form(nr=0)
#get the main form    

br.set_all_readonly(False)

for control in br.form.controls:
    print control

user_control = br.form.controls[0]
user_control._value = 'username'

user_password = br.form.controls[1]
user_password._value = 'password'

br.submit()
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Alexander
  • 147
  • 1
  • 4
  • 11

1 Answers1

1

One option would be to "transfer" cookies from mechanize to selenium and use selenium with a headless browser like PhantomJS or with a virtual display. Or, just switch to selenium+PhantomJS completely (including the authentication step).

See also:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Yes this is perfect. I switched to phantomjs and it was everything I could hope it could be and more. Ended up rewriting everything to selenium. Thanks a bunch! – Alexander Jul 01 '15 at 12:59