Cookie自动登录人人网

 1 import urllib2, cookielib,urllib
 2 
 3 class LoginRenren():        
 4     def __init__(self):
 5         self.log_url = "http://www.renren.com/PLogin.do"
 6         self.cj = cookielib.CookieJar()
 7         self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj))
 8         urllib2.install_opener(self.opener)
 9 
10     def login(self, email, password):
11         self.email = email
12         self.password = password
13         params = {"email":self.email, "password":self.password}
14         params = urllib.urlencode(params)
15         params = params.encode('utf-8') 
16         response = urllib2.urlopen(self.log_url, params)
17         file = open("E:\\renren.html", "wb")
18         file.write(response.read())
19 
20 def login(email = "[email protected]", password = "xxxxx" ):    
21     renren = LoginRenren()
22     renren.login(email, password)
23     
24 if __name__=="__main__":
25     print("main")
26     login()

 

你可能感兴趣的:(Cookie自动登录人人网)