How to login with python and save cookie, then use that info to view page for member only

Posted by patcsong on Stack Overflow See other posts from Stack Overflow or by patcsong
Published on 2012-07-10T02:52:24Z Indexed on 2012/07/10 3:15 UTC
Read the original article Hit count: 237

Filed under:

I am quite new in python and trying to write a script to login to the page at http://ryushare.com/login.python.

I have try many attempt, but it fails to login and i have no idea why. After login to the page, I wish to get the return of http://ryushare.com/file-manager.python

Here's the code I try to attempt by reading the example from others.

import urllib, urllib2, cookielib
username = 'myusername'
password = 'mypassword'

cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
login_data = urllib.urlencode({'login' : username, 'password' : password})
opener.open('http://www.ryushare.com/login.python', login_data)
resp = opener.open('http://ryushare.com/file-manager.python')
print resp.read()

I check the source code of the login page, it said the username and password value is "login and password" so i change it. I have try some other example which can be found here like google news feed, It also can not able to login : (

© Stack Overflow or respective owner

Related posts about python