Python 官方文档:入门教程 => 点击学习
#encode:utf-8 import urllib,urllib2,cookielib,JSON,time,md5,re class Renren(object): def __init__(self,em
#encode:utf-8
import urllib,urllib2,cookielib,JSON,time,md5,re
class Renren(object):
def __init__(self,email,passWord):
self.email=email
self.password=password
self.origURL='Http://www.renren.com/Home.do'
#self.origURL='http://apps.renren.com/happyfarm/'
self.domain='renren.com'
self.cj = cookielib.LWPCookiejar()
try:
self.cj.revert('renren,cookie')
except:
None
self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj))
urllib2.install_opener(self.opener)
def login(self):
params = {'email':self.email,'password':self.password,'origURL':self.origURL,'domain':self.domain}
req = urllib2.Request(
'http://www.renren.com/PLogin.do',
urllib.urlencode(params)
)
r = self.opener.open(req)
def friends(self):
req='http://friend.renren.com/myfriendlistx.do'
r=self.opener.open(req)
data = r.read()
f=re.search('friends=\[{.*?}\];',data)
x=f.group()
#print x
x=x[8:-1]
x=x.replace('tr','Tr')
x=x.replace('false','False')
friends=eval(x)
for i in range(len(friends)):
for key in friends[i].keys():
if key == 'name':
print key,eval("u'"+friends[i][key]+"'").encode('utf-8')
elif key == 'groups':
if len(friends[i][key]) != 0:
groups=friends[i][key][0]
print key,eval("u'"+groups+"'").encode('utf-8')
elif key == 'id':
req="http://www.renren.com/profile.do?id="+str(friends[i][key])
r = self.opener.open(req)
print eval("u'"+friends[i]['name']+"'").encode('utf-8')
else:
print key,friends[i][key]
a=Renren('账号,'密码')
a.login()
a.friends()
--结束END--
本文标题: python人人网遍历好友
本文链接: https://lsjlt.com/news/190644.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0