Python script for automatic logon to Renren

Source: Internet
Author: User

I want to share with you one of my ownPythonThe script for automatically logging on to Renren is no way to be lazy! Enter the account and password lazily, so that python can reduce the workload! Let's start with the script and talk about the knowledge points later:

#! /Usr/bin/ENV Python # encoding = utf-8import sysimport reimport urllib2import urllibimport cookielibclass Renren (object): def _ init _ (Self): Self. name = self. pwd = self. content = self. domain = self. origurl = ''self. operate = ''# the login operation object self. cj = cookielib. lwpcookiejar () Try: Self. CJ. revert ('renren. coockie ') Does T exception, E: Print e self. opener = urllib2.build _ opener (urllib2.httpcookieprocessor (S Elf. CJ) urllib2.install _ opener (self. opener) def setinfo (self, username, password, domain, origurl): ''' sets the user logon information ''' self. name = username self. pwd = PASSWORD self. domain = domain self. origurl = origurl def login (Self): ''' log on to Renren net''' Params = {'domain ': Self. domain, 'url url': Self. origurl, 'email ': Self. name, 'Password': Self. PWD} print 'login ....... 'req = urllib2.request ('HTTP: // www.renren.com/plogin.do', u Rllib. urlencode (Params) self. operate = self. opener. open (req) If self. operate. geturl () = 'HTTP: // www.renren.com/home.do': print 'logged on successfully! 'Self. CJ. save ('renren. coockie ') self. _ viewnewinfo () else: Print 'loged' on error 'def _ viewnewinfo (Self): ''' view the Update Status of a friend ''' self. _ caiinfo () def _ caiinfo (Self): ''' collection information''' h3patten = Re. compile ('

  

Mainly usedPython cookielib, Urllib2, urllib, these three modules are Python's better HTTP modules.

 

self.cj = cookielib.LWPCookieJar()try:    self.cj.revert('renren.coockie')except Exception,e:    print e     self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj))urllib2.install_opener(self.opener)

  

These rows are cookies for the local Renren network, because Renren needs to verify cookies to log on. If you run this script, a program in the current directory will automatically create a Renren. cookie.

Renren. cookie Information is: # LWP-Cookies-2.0 Set-Cookie3: webonlinenotice_244225225 = 1; Path = "/"; domain = ".renren.com"; path_spec; domain_dot; expires = "2010-04-11 06: 59: 33z "; version = 0. To sum up, if you want to use cookies for website login, you need to use the cookielib module. Otherwise, you cannot log on to the website using a program, and you need to write an urlib example during the expiration time, you can use the script above for fun! ExperiencePython Renren codeFun! If you are interested in the Web, you can see: Use Python beautifulsoup to parse web pages, Python beautifulsoup multi-thread analysis to capture web pages

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.