python 抓取腾讯微博数据并做简单的分析
来源:互联网 发布:nodejs高级编程 中文 编辑:程序博客网 时间:2024/06/13 10:29
利用python去读取腾讯微博中某个人的数据,统计和他相关的一些连接,并对每个打印每个连接的数据,本人采用的python版本为3.3.
from html.parser import HTMLParser import urllib.requestimport repattern = re.compile(r'http://t.qq.com/*?')class MyParser(HTMLParser): a_txt =False total = 0 sample_list = [] def inputSelfAddress(self, name): self.sample_list.append(name) def __init__(self): HTMLParser.__init__(self) def handle_starttag(self, tag, attrs): if tag=='div': for name,value in attrs: if (name == 'class')and(value == 'msgCnt'): self.a_txt=True if tag=='a': for name, value in attrs: if(name == 'href'): match = pattern.match(value) if(match): if value in self.sample_list: return else: self.total=self.total+1 self.sample_list.append(value) def handle_data(self, data): if self.a_txt: print (data) self.a_txt=False headers = ('User-Agent','Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11')opener = urllib.request.build_opener()opener.addheaders = [headers]strAddress = "http://t.qq.com/xiaoRainie"fp =opener.open(strAddress)mybytes = fp.read()mystr = mybytes.decode("utf8")fp.close()myparser = MyParser()myparser.inputSelfAddress(strAddress)myparser.feed(mystr) print("总数:", myparser.total-11)for i in range(int(myparser.total), 1, -1): print(myparser.sample_list[i-1])print("结束")for i in range(int(myparser.total), 1, -1): fp =opener.open(myparser.sample_list[i-1]) myparser.inputSelfAddress(myparser.sample_list[i-1]) mybytes = fp.read() mystr = mybytes.decode("utf8") fp.close() myparser = MyParser() myparser.feed(mystr)
这里简单使用了python 的html 分析模块,和url 处理模块!
- python 抓取腾讯微博数据并做简单的分析
- python 抓取腾讯微博数据并做简单的分析 .
- Python抓取360手机市场APP信息并做简单分析
- python抓取新浪微博评论并分析
- 腾讯微博数据抓取(java实现)
- 使用python抓取并分析数据-链家网(上)
- 使用python抓取并分析数据-链家网(下)
- 利用python抓取搜狗关于数据分析的文章并保存到csv文件
- 网页数据抓取并分析
- [jjzhu学python]之使用python抓取拉勾网职位信息并做简单统计分析
- 数据抓取分析(python + mongodb)Python数据抓取分析
- Fiddler抓取数据并分析(完整的配置教程)
- python抓取省市区的数据并保存到mysql中
- 简单的数据抓取
- 网页抓取数据并分析,特别包括分页数据的抓取。
- 网页抓取数据并分析,特别包括分页数据的抓取
- python | 简单的数据分析
- scrapy抓取腾讯招聘数据并入库mongodb(浅)
- js中调用AS莫名其妙的错误,不得使用的关键词
- iOS7新特征汇总[04]新特征介绍4
- ArcGIS Server 10.1新特性-- 发布服务
- Handling IRPs: Definition 2: IRP as a Thread-Independent Call Stack
- c#之执行SQL存储过程
- python 抓取腾讯微博数据并做简单的分析
- 数据结构要点归纳总结(转)
- Error: C3065E: type of input file 'XXX' unknown——已解决!
- Handling IRPs 3: Passing an IRP to the Next Lower Driver
- Handling IRPs 4: Completing an IRP
- 开发者所需要知道的iOS7 SDK新特性
- Handling IRPs 5: Synchronous I/O Responses
- 访问存储设备
- [黑马程序员]对两个整数变量的值进行交换的方法总结