This article describes the Python implementation of automatic login Renren and access to the recent visitors to the method, to share for your reference.
The specific methods are as follows:
##-*-CODING:GBK-*-#在 import os from xml.dom import minidom import re import urllib import urllib2 Import Cookielib Import datetime Import time from urllib2 import urlerror,httperror #登录模块 def Renren_login found on the Web (logfile,us Ername,password): Logfile.write (str (Datetime.datetime.now ()) + ' renren/r/n ') CJ = Cookielib. Cookiejar () Post_data = Urllib.urlencode ({' Email ': username, ' password ':p assword,}) path = ' H Ttp://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 ' Logf Ile.write (' urlerror: ' + str (e.code) + '/r/n ') return False except Httperror,e:logfile.write (' HTTP Error: ' + E.reason + '/r/n ') return False if conn.geturl () = = ' Http://www.renren.com/home ': print ' success ' Logfil E.write (' Task finish 'ed/r/n ') Open (' login_renren.html ', ' W '). Write (Conn.read ()) return Conn.read () else:print ' Task Failed ' Logfile.write (' Task failed/r/n ') #生成的登录日志文件 file_object = open ("Log.txt", "w") Login_index = Renren_login (fi Le_object, ' username ', ' password ' #这地方换成登录的用户名和密码 #parse parse Web page r1 = re.compile ("") http://www.renren.com/profile.do\?portal=home FOOTPRINT&REF=HOME_FOOTPRINT&ID=\D{9} ' ") Li = R1.findall (open (" login_renren.html "," R "). Read ()) # Place the nearest visited address into the dictionary url_dict ={}for item in Li:print item Url_dict.setdefault (item) #访问最近来访者 for item in Url_dict.iterkeys
(): Os.startfile (item)
I hope this article will help you with your Python programming.