Matt D Matt D - 8 months ago 48
Python Question

Login with python mechanize

I am trying to create a python script that uses mechanize to submit data to a web form.

This is what I have so far

import mechanize

username = <my_username>
password = <my_password>
url = <my_url>

print "opening browser"
br = mechanize.Browser()
print "opening url...please wait"
print br.title()
print "selecting form"
br['UserID'] = username
br['PassPhrase'] = password
print "submitting form"

I'm stuck on what to do now. Does
now contain the next webpage than comes up after submitting the form? Is there a way I can print the
to check what webpage is in it? (I cant use
print br.title()
because both pages have the same title)

Answer Source

Try this at the end:

response = br.submit()

pageSource should give you the html-source of the post-login page.