我尝试登录并从即将到来的网页获取网址:
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()
......到目前为止一切顺利。现在我需要一个来自重定向页面的URL,任何帮助吗?
答案 0 :(得分:4)
br.geturl()
应该这样做。使用httpbin.org's重定向端点进行测试:
br = mechanize.Browser()
url = 'http://httpbin.org/redirect-to?url=http%3A%2F%2Fstackoverflow.com'
br.open( url )
>>> print br.geturl()
http://stackoverflow.com