Python Renren login application instance

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.