1 #encoding:utf-8
2 import urllib,urllib2,cookielib,re,time
3 class renren():
4 def __init__(self,email,password):
5 self.url='http://www.renren.com/'
6 self.email=email
7 self.password=password
8 self.cookie=cookielib.LWPCookieJar()
9 self.opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookie))
10 self.friendIdList=[]
11 def login(self):
12 url=self.url+'PLogin.do/'
13 params=urllib.urlencode({'email':self.email,'password':self.password})
14 response=self.opener.open(urllib2.Request(url,params))
15 url=self.url+'home'
16 if response.geturl()==url:
17 print 'Login Succesfully!'
18 self.cookie.save('xiaonei.coockie')
19 else:
20 print 'Login Failed'
21
22 def changeState(self):
23 pass
24
25 def getFriendList(self):
26 url='http://friend.renren.com/myfriendlistx.do'
27 response=self.opener.open(urllib2.Request(url))
28 html=response.read()
29 friend=str(re.search('friends=\[{.*}\]',html).group())
30 friendId=re.findall('"id":\d+',friend)
31 for id in friendId:
32 self.friendIdList.append(id.lstrip('"id":'))
33
34 def browseFriend(self):
35 cnt=0
36 for friendId in self.friendIdList:
37 cnt+=1
38 url='http://www.renren.com/profile.do?id='+'%s'%(friendId)
39 urllib2.Request(url)
40 time.sleep(1)
43 if __name__=='__main__':
44 app=renren('your email','your password')
45 app.login()
46 app.changeState()
47 app.getFriendList()
48 app.browseFriend()
49
50
changeState 因为不知道怎么分析校内的表单提交方式,他的源码没法查看出表单时提交到哪里了,所以不好写,而类似getFriendList,访问好友啊这样的操作则是可以的,同样还可以写日志啊什么的。
有谁能告诉我怎么分析校内这种隐藏的表单
<input type="submit" autocomplete="false" id="publisher_submit" class="submit" value="发布" stats="Pub_Send">
是后台的js代码么
不过话说回来,python的urllib,urllib2什么的倒是很好用,做一些相关的应用都是很简单的