This article mainly introduces the python Renren logon application instance, which is a very practical technique. If you need it, you can refer to the example below to describe how to implement the python Renren login application, share it with you for your reference.
The specific method is as follows:
Import re import urllib import urllib2 import cookielib import datetimeimport timefrom urllib2 import URLError, HTTPError # The first parameter is the log file, the second parameter is the user name, and the third parameter is the password def renren_login (logfile, username, password): logfile. write (str (datetime. datetime. now () + 'renren/r/N') cj = cookielib. cookieJar () post_data = urllib. urlencode ({'email ': username, 'Password': password,}) path =' http://www.renren.com/PLogin.do 'Opener = urllib2.build _ opener (cipher (cj) urllib2.install _ opener (opener) req = urllib2.Request (path, post_data) try: conn = urllib2.urlopen (req) limit t URLError, e: print 'urlerror 'logfile. write ('urlerror: '+ str (e. code) + '/r/N ')# http://www.renren.com/SysHome.do Return False handle T HTTPError, e: logfile. write ('HTTP Error: '+ e. reason +'/r/N') return False if conn. geturl () =' http://www.renren.com/home ': Print 'success' logfile. write ('Task finished/r/N') return conn. read () else: print 'Task failed' logfile. write ('Task failed/r/N') # log on successfully. The Code file_object = open ("log.txt", 'w') login_index = renren_login (file_object, 'xxxxxx', 'xxxx ')
I hope this article will help you with Python programming.