Python Renren Login Application instance _python

Source: Internet
Author: User

This article describes the Python Renren login application of the implementation method, share for everyone to reference.

The specific methods are as follows:

Import re import urllib import urllib2 import cookielib import datetime import time from URLLIB2 import urlerror,http Error #第一个参数为日志文件, the second parameter is user name, and the third parameter is 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 ':p assword,}) 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) except Urlerror,e:print ' Urlerror ' LOGFILE.WR Ite (' Urlerror: ' + str (e.code) + '/r/n ') #http://www.renren.com/syshome.do return False except HTTPERROR,E:LOGF Ile.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 ') # login succeeded, return the entire page code file_object = open ("Log.txt", ' W ') Login_index

 = Renren_login (File_object, ' xxxxxx ', ' xxxx ')

I hope this article will help you with your 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.