评论抓取:Python爬取微信在APPStore上的评论内容及星级
#完整程序如下:
import requests
import re def getHTMLText(url):
try:
r = requests.get(url)
r.raise_for_status()
r.encoding = r.apparent_encoding
return r.text
except:
return '' def printAPPName(html):
try:
pattern = re.compile(r'{"im:name":{"label":(.*?)}, "rights"', re.S)
#如果不使用re.S参数,则只在每一行内进行匹配,如果一行没有,就换下一行重新开始,不会跨行。
#而使用re.S参数以后,正则表达式会将这个字符串作为一个整体,将“\n”当做一个普通的字符加入到这个字符串中,在整体中进行匹配
APPName = re.findall(pattern, str(html))
return 'APPName:' + str(APPName)
except:
return '' def fillUnivlist(titles, comments, stars, html):
try:
pattern = re.compile(r'"title":{"label":(.*?)}, "content"', re.S) #提取标题
nbaInfo = re.findall(pattern, str(html)) #提取title # findStr = '"title":{"label":'
# nbaInfo = nbaInfo1[nbaInfo1.find(findStr)+len(findStr):]
patternFloor = re.compile(r'"content":{"label":(.*?), "attributes":{"type":"text"}}', re.S) #提取content
floorText = re.findall(patternFloor, str(html)) patternStar = re.compile(r'"im:rating":{"label":(.*?)}, "id"', re.S) # 提取星级
star = re.findall(patternStar, str(html))
# print(str(star)) number = len(nbaInfo)
print(number)
for i in range(number):
Info = nbaInfo[i] #利用Tools类移除不想要的格式字符
if i==0:Info = Info[Info.find('"title":{"label":')+len('"title":{"label":'):]
# print(Info)
Info1 = floorText[i]
Info2 = star[i]
# print(Info2+"hello")
titles.append('title:' + Info)
comments.append('content:' + Info1)
stars.append('star:' + Info2)
except:
return '' def writeText(titleText, fpath):
try:
with open(fpath, 'a', encoding='utf-8') as f:
f.write(str(titleText)+'\n')
f.write('\n')
f.close()
except:
return '' def writeUnivlist(titles, comments, stars, fpath, num):
with open(fpath, 'a', encoding='utf-8') as f:
for i in range(num):
f.write(str(stars[i]) + '\n')
f.write('*' * 10 + '\n')
f.write(str(titles[i]) + '\n')
f.write('*' * 50 + '\n') #输入一行*号
f.write(str(comments[i]) + '\n')
f.write('*' * 100 + '\n')
f.close() def main():
count = 0
url = 'https://itunes.apple.com/rss/customerreviews/page=1/id=414478124/sortby=mostrecent/json?l=en&&cc=cn' #要访问的网址
output_file = 'D:/StockInfo.txt' #最终文本输出的文件
html = getHTMLText(url) #获取HTML
APPName = printAPPName(html)
writeText(APPName, output_file)
for i in range(10):
i = i + 1
titles = []
comments = []
stars = []
url = 'https://itunes.apple.com/rss/customerreviews/page=' + str(i) + '/id=414478124/sortby=mostrecent/json?l=en&&cc=cn'
html = getHTMLText(url)
fillUnivlist(titles, comments, stars, html)
writeUnivlist(titles, comments, stars, output_file, len(titles))
count = count + 1
print("\r当前进度: {:.2f}%".format(count * 100 / 10), end="") if __name__ == '__main__':
main() #如果想爬取其他APP只需要改变id的值,如想爬腾讯的,只需将id=414478124换成id=444934666
#另外本程序是模仿https://www.cnblogs.com/sea-ocean/p/6601421.html的
评论抓取:Python爬取微信在APPStore上的评论内容及星级的更多相关文章
- python爬取微信小程序(实战篇)
python爬取微信小程序(实战篇) 本文链接:https://blog.csdn.net/HeyShHeyou/article/details/90452656 展开 一.背景介绍 近期有需求需要抓 ...
- Python爬取微信小程序(Charles)
Python爬取微信小程序(Charles) 本文链接:https://blog.csdn.net/HeyShHeyou/article/details/90045204 一.前言 最近需要获取微信小 ...
- Python学习-使用Python爬取陈奕迅新歌《我们》网易云热门评论
<后来的我们>上映也有好几天了,一直没有去看,前几天还爆出退票的事件,电影的主题曲由陈奕迅所唱,特地找了主题曲<我们>的MV看了一遍,还是那个感觉.那天偶然间看到Python中 ...
- Python爬取豆瓣《复仇者联盟3》评论并生成乖萌的格鲁特
代码地址如下:http://www.demodashi.com/demo/13257.html 1. 需求说明 本项目基于Python爬虫,爬取豆瓣电影上关于复仇者联盟3的所有影评,并保存至本地文件. ...
- python 爬取微信好友列表和个性签名,绘制个性签名云图
python爬取微信好友列表和个性签名,绘制个性签名云图 1. 简要介绍 本次实验主要用到下面几个库 : 1)itchat---用于微信接口,实现生成QR码,用于微信扫描登陆 2)re(正则化)--- ...
- python 爬取豆瓣电影评论,并进行词云展示及出现的问题解决办法
本文旨在提供爬取豆瓣电影<我不是药神>评论和词云展示的代码样例 1.分析URL 2.爬取前10页评论 3.进行词云展示 1.分析URL 我不是药神 短评 第一页url https://mo ...
- 用Python爬取了三大相亲软件评论区,结果...
小三:怎么了小二?一副愁眉苦脸的样子. 小二:唉!这不是快过年了吗,家里又催相亲了 ... 小三:现在不是流行网恋吗,你可以试试相亲软件呀. 小二:这玩意靠谱吗? 小三:我也没用过,你自己看看软件评论 ...
- Python爬取跑男的评论,看看大家都在看谁吧
本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理. 以下文章来源于菜J学Python,作者: J哥 Python爬取爬取腾讯视频弹幕视频讲解 http ...
- 复仇者联盟3热映,我用python爬取影评告诉你它都在讲什么
Python(发音:英[?pa?θ?n],美[?pa?θɑ:n]),是一种面向对象.直译式电脑编程语言,也是一种功能强大的通用型语言,已经具有近二十年的发展历史,成熟且稳定.它包含了一组完善而且容易理 ...
随机推荐
- ASP.NET中相对路径的使用总结
如果有一个网站上的图片的路径是这样的: http://localhost:2008/websit1/images/1.jpg websit1表示的是虚拟路径或者是站点 在asp.net中,如果我们在. ...
- day13<常见对象+>
常见对象(StringBuffer类的概述) 常见对象(StringBuffer类的构造方法) 常见对象(StringBuffer的添加功能) 常见对象(StringBuffer的删除功能) 常见对象 ...
- POJ 1947 Rebuilding Road(树形DP)
Description The cows have reconstructed Farmer John's farm, with its N barns (1 <= N <= 150, n ...
- swift--Timer实现定时器功能,每个一段时间执行具体函数,可以重复,也可以只执行一次
1,创建 //控制器 timer = Timer.scheduledTimer(timeInterval: 0.001, target: self, selector: #selector(Fifte ...
- ScrollView:ScrollView can host only one direct child异常
java.lang.IllegalStateException: ScrollView can host only one direct child 原因是在外面有一个TextView控件,将其删除则 ...
- 07python之字符串的常用方法
字符串作为python中常用的数据类型,掌握字符串的常用方法十分必要. 常用知识点: 1.字符串的3种格式化方法 2.字符串的strip()方法 3.字符串的join()方法 4.字符串可以切片 1. ...
- 前端 ui 框架
Bootstrap:http://getbootstrap.com/css/ ant-design:https://ant.design/ weui:https://weui.io/ amazeui: ...
- Hbase的基本认识
1.使用场景:实时查询交互 说说概念性的东西,方便今后更加深入的理解. HBase是Apache Hadoop中的一个子项目,Hbase依托于Hadoop的HDFS作为最基本存储基础单元,通过使用ha ...
- getViewTreeObserver
在项目中或多或少会遇一一些异步的操作,比如自定中不能马上获取到高度用测试可以得到.. final View headerView = View.inflate(this, R.layout.layou ...
- C++11新特性之一——Lambda表达式
C++11新特性总结可以参考:http://www.cnblogs.com/pzhfei/archive/2013/03/02/CPP_new_feature.html#section_6.8 C++ ...