Python Renren login application instance, python Renren application instance
This article describes how to implement the python Renren logon application and 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 (urllib2.HTTPCookieProcessor (cj )) urllib2.install _ opener (opener) req = urllib2.Request (path, post_data) try: conn = urllib2.urlopen (req) failed 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.
How can I handle the verification code for python Renren's Automatic Logon? Otherwise, automatic logon cannot be implemented.
What should I do if I encounter a verification code? There are two solutions:
-
1. google's verification code, cool
-
2. simple verification code: the number of characters is limited. It only uses simple translation or rotation to add noise without being distorted. This kind of verification code can still be processed. The general idea is to rotate it back, noise Removal,
Divide a single character, divide it, and then use the feature extraction method (such as PCA) to reduce the dimension and generate a feature library, and then compare the verification code with the feature library. This is complicated. I can't finish a blog post.
.
-
3. In fact, some verification codes are still very weak. I won't name them here. Anyway, I have extracted very accurate verification codes through the 2 method, SO 2 is actually feasible.
How to Use Python to change the information of the website to be logged on
The general idea is to capture packets First, analyze the content of the login package and the data packet returned by the server, and then write it in Python. You can use urllib2, cookiejar, and beautifulsoup (this is used to analyze Web pages. Of course, it is more efficient to construct a class using regular expressions.