查找某人在某微博裏留下的所有留言
2016-03-30 12:34
471 查看
#coding=utf-8 __author__ = 'user' import requests import sys import re import time def getcomment(url,cook,commentid): urlre=requests.get(url,cookies=cook) html=urlre.text cook2=urlre.cookies print(html.encode('utf-8')) print('') mystate2=re.findall('</a> <a href="http://weibo.cn/comment/(.*?)&rl=0#cmtfrm(.*?)</a>',html,re.S) k=0 f=open('1.txt','r') a=f.read() f.close() f=open('1.txt','w+') f.write(a) for i in mystate2: k=k+1 meow=re.findall('\[(.*?)\]',i[1],re.S) if meow[0]!='0': ans=re.search(commentid,i[0]) if ans: commentlink='http://weibo.cn/comment/'+i[0]+'&rl=0#cmtfrm' #print (k) #print (commentlink) f.write(commentlink+'\n') f.close() print (k) if k<1: time.sleep(2) getcomment(url,cook,commentid) if __name__=='__main__': cook={"Cookie":""} for i in range(1,76+1): print('start%d'%i) url='http://weibo.cn/u/111111?page=%d'%i commentid='111111' getcomment(url,cook,commentid)
</pre><pre name="code" class="python"><pre name="code" class="python">#coding=utf-8 __author__ = 'user' import requests import sys import re import time #<meta http-equiv="refresh" def readtxt(): k=0 ff=open('1.txt','r') a=ff.readline() while a: k=k+1 print(k) if k>=1: print(a) test(a,a) a=ff.readline() ff.close() def test(url0,url): cook={"Cookie":""} urlre=requests.get(url,cookies=cook) html=urlre.text print('read') if re.search('comment',html,re.S): zy=re.search('123456',html,re.S) if zy: f=open('2.txt','r') text=f.read() f.close() f=open('2.txt','w+') f.write(text) f.write(url0+'\n') f.close() else: nexturl=re.search('method="post"><div><a href="(.*?)">',html,re.S) if nexturl: nexturl=nexturl.group(1) nexturl='http://weibo.cn'+nexturl nexturl=re.sub('&','&',nexturl) test(url0,nexturl) else: print(html.encode('utf-8')) else: time.sleep(1) test(url0,url) if __name__=='__main__': readtxt()
最後123456在111111的微博下留下的留言的LINK都在2.txt中了。
相关文章推荐
- 版本控制器git学习
- js插件实现步骤
- DES 加密算法
- Go语言学习五:数组与传递到函数的数组
- Unity5.x的GUIText被UI Text所取代--增加头文件UnityEngine.UI
- 身体各个部位的日语单词
- Unity3d游戏中自定义贝塞尔曲线编辑器[转]
- POJ 2484 A Funny Game【博弈】
- POJ 2484 A Funny Game【博弈】
- Linux的SOCKET编程详解
- tomcat 部署web步骤
- 蓝桥杯省赛结果
- ExtJS 常用组件属性 及使用方法
- Linux 重点补充
- 解决Mysql报错:PHP Warning: mysql_connect(): mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication.
- 通过dubbo暴露接口调用方法,及基于zookeeper的dubbo涉及配置文件
- [置顶] RxJava之并发处理(SerializedSubject)
- XAudio2音量和音调控制
- typedef
- 设置DEBUG模式