- # encoding=utf-8
- import urllib, urllib2, cookielib, re, time
- cookie = {"t": "此处填写Session字段的t属性"}
- cookie = "".join(x + "=" + cookie[x] + ";" for x in cookie)
- opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar()))
- urllib2.install_opener(opener)
- req = urllib2.Request("http://friend.renren.com/myfriendlistx.do#item_0")
- req.add_header('Cookie', cookie)
- content = urllib2.urlopen(req).read()
- with open("page.html", "w") as f:
- f.write(content)
- myid = "此处填写你的id"
- Token = re.findall('get_check:\\'[\\d-]*\\'?',content)[0].split(':')[1].strip('\\'')
- rtk = re.findall('get_check_x:\\'.*?\\'',content)[0].split(':')[1].strip('\\'')
- line = re.findall('var friends.*?;',content)[0]
- print Token
- print rtk
- ID = []
- NAME = []
- i = 0
- while i<len(line):
- if line[i:i+2]=='id':
- ID.append(line[i+4:i+13])
- if line[i:i+4]=='name':
- j = i+7
- string = ""
- while line[j]!='"':
- string = string+line[j]
- j = j+1
- NAME.append(string)
- i = i+1
- print len(ID)
- #此处status内容可以随意改,也可以改成一条status里@多个好友,大家自己看着改吧
- i = 0
- while i<len(ID):
- status = '@'+NAME[i].decode('unicode_escape')+'('+ID[i]+')'+' '
- status = status.encode('utf-8')
- params = {'content':status,'hostid':myid,'channel':'renren','requestToken':Token,'_rtk':rtk}
- req = urllib2.Request("http://shell.renren.com/"+myid+"/status",
- urllib.urlencode(params)
- )
- req.add_header('Cookie', cookie)
- content = urllib2.urlopen(req).read()
- time.sleep(3)
- i = i+1
- print i
- #该片段来自于http://www.codesnippet.cn/detail/180720134668.html
来源: http://www.codesnippet.cn/detail/180720134668.html