How do I get the current url from Mechanize in Python?
I am trying to login and get the url on the next page:
br = mechanize.Browser()
url = "http://www.blahblah.com/login-page/"
br.open( url )
br.select_form(nr = 1)
br.form['username'] = "Foo"
br.form['password'] = "fooPswRd"
br.submit()
... so far so good. Now I need the url from the redirected page, any help?
+3
source to share
1 answer
br.geturl()
should do it. Using httpbin.org to redirect the endpoint:
br = mechanize.Browser()
url = 'http://httpbin.org/redirect-to?url=http%3A%2F%2Fstackoverflow.com'
br.open( url )
>>> print br.geturl()
http://stackoverflow.com
+4
source to share