开发者

Python Mechanize: Session has expired

开发者 https://www.devze.com 2023-04-11 21:56 出处:网络
Trying out mechanize to scrape some content off an https asp site, it looks as if the login page submission works as I get returned a 200.But when I try and open a url p开发者_如何学编程resumably usin

Trying out mechanize to scrape some content off an https asp site, it looks as if the login page submission works as I get returned a 200. But when I try and open a url p开发者_如何学编程resumably using the cookie captured after the login, I get re-directed back to the login page with the error that my session has expired. The last print is just so I can see that I get redirected.

import mechanize 

USER_AGENT = "Mozilla/5.0 (X11; U; Linux i686; tr-TR; rv:1.8.1.9) Gecko/20071102 Pardus/2007 Firefox/2.0.0.9"

mech = mechanize.Browser()
mech.addheaders = [("User-agent", USER_AGENT)]

mech.open("https://www.example.com/login.asp")

mech.select_form("loginform")
mech['id'] = "blah"
mech['pin'] = "blah"
response = mech.submit()

trueContent = mech.open("https://www.example.com/content")

print trueContent.geturl()


Your code looks good to me however I don't see any check that login was successful

response = mech.submit()

Look at the content of response to make sure your login was successful.

Are you sure this site works without javascript? There could be hidden field that are set by javascript.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号