# -*- coding: utf-8 -*-
import urllib
import urllib2
import cookielib
def login():
#cookie
cj=cookielib.LWPCookieJar()
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
#login information
url='http://www.renren.com/Login.do?rf=r&domain=renren.com&origURL=http%3A%2F%2Fwww.renren.com%2FHome.do'
email='[email protected]'
password='tttddd'
headers={'Content-Type': 'application/x-www-form-urlencoded'}
v_count={'email':email,'password':password,'submit':'登入'}
data=urllib.urlencode(v_count)
res=opener.open(url,data)
print res.geturl() # 'Get the url after login, it can be used to check whether it login successfully or not.'
if __name__=='__main__':
login()
|