Python implements automatic login for Renren and access to recent visitor instances _python

Source: Internet
Author: User
Tags datetime

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.

Related Article

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.