用python写的人人网遍历好友脚本

import sys,re,urllib2,urllib,cookielib,os
import cPickle as p


class Renren(object):
'''for users of renren.
get friendlist, download all the photos of the friend'''
version='1.0'
def __init__ (self):
self.name=self.pwd=self.content=self.origURL=''
self.operate=''
self.cj=cookielib.LWPCookieJar()
if os.path.isfile('renren.coockie'):
self.cj.revert('renren.coockie')
self.opener=urllib2.build_opener( urllib2.HTTPCookieProcessor(self.cj))
urllib2.install_opener(self.opener)


def setinfo(self,username,password,origURL):
self.name=username
self.pwd=password
self.origURL=origURL


def login(self):
'''login in the renren.com

sucess return 0; fail return -1'''
params={'email':self.name,'password':self.pwd}
print ('login...')
req=urllib2.Request("http://www.renren.com/PLogin.do",urllib.urlencode(params))
self.operate=self.opener.open(req)
if self.operate.geturl()==self.origURL:
print ('ok!')
self.cj.save('renren.coockie')
return 0
else:
print ('fail!')
return -1




def getfriendIDs(self):
'''Get the ID of the friends'''
friendfile=file('friendlist.txt','w')
friendlist=''
URL_FRIENDLIST='http://friend.renren.com/myfriendlistx.do'
result=self.opener.open(URL_FRIENDLIST)
html=result.read()
reg='"id":\d\d\d\d\d\d\d\d\d'
for f in re.finditer(reg,html):
x=f.group()
x=x[5:]
print 'Get user ID success:',x
friendlist=friendlist+'\n'+x
friendfile.write(friendlist)
friendfile.close()
def Freshpage(self):
urls='http://www.renren.com/'
friendfile=file('friendlist.txt','r')
n=0;
for friend in friendfile.readlines():
req=urllib2.Request(urls+friend)
rsp=urllib2.urlopen(req)
n=n+1;
print n,':',friend
#thepage=rsp.read()
friendfile.close()


        def AD(self):
            urls='http://www.renren.com/248480792'
            word="hello world!"
            params={'title':word,'body':word}
            req=urllib2.Request("http://blog.renren.com/NewEntry.do",urllib.urlencode(params))
            self.operate=self.opener.open(req)
            self.operate.geturl()
            #print self.operate.geturl()









#renren home page fresh scrip

#edit by Jeff xu 
#jeff890309@gmail.com
from renren2 import *
import getpass


ren=Renren()
urls='http://www.renren.com/'
while True:
print 'Input user name:'
username=raw_input()
print 'Input user ID:'
userID=raw_input()
        password=getpass.getpass("password:")
origURL='http://www.renren.com/'+userID
ren.setinfo(username,password,origURL)
if not ren.login():
break
ren.getfriendIDs()
ren.Freshpage()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值