Python学习:Python分析钉钉评论(一)爬取数据

爬取数据

从App Store官网拿下评论数据做分析

App Store评论API:
https://itunes.apple.com/rss/customerreviews/page=1/id=/sortby=mostrecent/json?l=en&&cc=cn

钉钉在App Store的评论API:
https://itunes.apple.com/rss/customerreviews/page=1/id=930368978/sortby=mostrecent/json?l=en&&cc=cn

打开后发现对我们有用的数据就只有用户评分、评论标题、评论内容:
Python学习:Python分析钉钉评论(一)爬取数据_第1张图片
这仅是第一页的评论,通过测试发现最多可以查看10页的评论。

将数据保存到excel:

import requests
import pandas as pd
POPULATION_EXCEL_PATH = '钉钉评论.xlsx'

flag = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
urllist = []
for i in flag:
    url = f"https://itunes.apple.com/rss/customerreviews/page={i}/id=930368978/sortby=mostrecent/json?l=en&&cc=cn"
    urllist.append(url)
rating = []  # 评分
title = []  # 标题
content = []  # 内容
for url in urllist:
    res = requests.get(url)
    data = res.json()['feed']['entry']
    for i in range(len(data)):
        rating.append(data[i]['im:rating']['label'])
        title.append(data[i]['title']['label'])
        content.append(data[i]['content']['label'])
data = {'打分': rating, '标题': title, '内容': content}

df = pd.DataFrame(data)
writer = pd.ExcelWriter(POPULATION_EXCEL_PATH)
df.to_excel(excel_writer=writer, index=True,
            encoding='utf-8', sheet_name='钉钉评论数据')
writer.save()
writer.close()

查看excel保存的数据(按评分高低排序后):
Python学习:Python分析钉钉评论(一)爬取数据_第2张图片

学习参考微信公众号:早起python

你可能感兴趣的:(Python学习:Python分析钉钉评论(一)爬取数据)