一:页面元素分析:
1.在猫眼上找到《狮子王》:
https://maoyan.com/films/1189879
然后往下拉web端只有10条评论,那我们要获取所有评论。
2.首选m站(找评论接口):
f12,选手机端(我chrom的手机端在左上角第二个),然后选XRH(记得勾上Preserve log)
然后往下拉,每刷新一次api的变化
http://m.maoyan.com/review/v2/comments.json?movieId=1189879&userId=-1&offset=0&limit=15&ts=0&type=3
http://m.maoyan.com/review/v2/comments.json?movieId=1189879&userId=-1&offset=15&limit=15&ts=1563018929470&type=3
http://m.maoyan.com/review/v2/comments.json?movieId=1189879&userId=-1&offset=30&limit=15&ts=1563018929470&type=3
http://m.maoyan.com/review/v2/comments.json?movieId=1189879&userId=-1&offset=45&limit=15&ts=1563018929470&type=3
可以看出每页的评论数由limit限制为15个,即每刷新一次offset+15,userId=-1,ts=1563018929470每次都不变的
3.访问api找到可用数据(我装了chrom的一个json插件,前面博客有):
3.1:http://m.maoyan.com/review/v2/comments.json?movieId=1189879&userId=-1&offset=15&limit=15&ts=1563018929470&type=3
3.2:http://m.maoyan.com/review/v2/comments.json?movieId=1189879&offset=15
url=http://m.maoyan.com/review/v2/comments.json?movieId=1189879&(offset+=15)
我们发现这个api的数据有点少,没有城市,评论日期还是:startTime: “1563030900000”,
4.重新找个api
这个是app端的api,此时offset就是页数了,每次+1,每页有25条
http://m.maoyan.com/mmdb/comments/movie/1189879.json?v=yes&offset=0
cmts: [
{
approve: 0,
approved: false,
assistAwardInfo: {
avatar: "",
celebrityId: 0,
celebrityName: "",
rank: 0,
title: ""
},
avatarurl: "https://img.meituan.net/maoyanuser/0838db48f5da3a1b7f2e540c31d580697189.jpg",
cityName: "海门",
content: "看完后不想走,小孩说还想看一遍。很好看。",
filmView: false,
id: 1071348361,
isMajor: false,
juryLevel: 0,
majorType: 0,
movieId: 1189879,
nick: "宁静",
nickName: "宁静",
oppose: 0,
pro: false,
reply: 0,
score: 5,
spoiler: 0,
startTime: "2019-07-13 23:31:36",
supportComment: true,
supportLike: true,
sureViewed: 1,
tagList: {
fixed: [
{
id: 1,
name: "好评"
},
{
id: 4,
name: "购票"
}
]
},
time: "2019-07-13 23:31",
userId: 1246404874,
userLevel: 2,
videoDuration: 0,
vipType: 0
},
要抓取的数据:
评论时间:time
评论昵称:nickName
性别:gender
所在城市:cityName
内容:content
猫眼等级:userLevel
评分:score