Python automatically logs on to Renren and collects information.
This example describes how to use python to automatically log on to Renren and collect information. Share it with you for your reference. The specific implementation method is as follows:
#! /Usr/bin/python #-*-coding: UTF-8-*-import 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.HTTPCookieProce Ssor (self. 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/PLog In. do ', urllib. urlencode (params) self. file = urllib2.urlopen (req ). read () newsfeed = open('news.html ', 'w') try: newsfeed. write (self. file) failed t Exception, e: newsfeed. close () self. operate = self. opener. open (req) print type (self. operate) print self. operate. geturl () if self. operate. geturl (): print 'loged' 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 ('<article> (. *?) </Article> ') # The matching range is apatten = re. compile ('
I hope this article will help you with the Python sequence design.