1 Star 0 Fork 185

不清白 / Python爬虫

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
爬取《悲伤逆流成河》猫眼信息.py 1.92 KB
一键复制 编辑 原始数据 按行查看 历史
import requests
from fake_useragent import UserAgent
import json
import pymongo
#保存到数据库
clien=pymongo.MongoClient(host='填写数据库IP')
db=clien.The_cat_s_eye_essay
coll=db.eye_essay
#创建一个随机生成user-aengt的对象
ua=UserAgent()
#提取我们要的短评
def parse_json(json):
if json:
items=json.get('cmts')
i=0
for item in items:
data={
'ID':item.get('nickName'),
'短评':item.get('content'),
'评分':item.get('score'),
'用户地点':item.get('cityName'),
'评论时间':item.get('startTime'),
'回复数':item.get('reply'),
'性别':item.get('gender')
}
#coll.insert_one(data)
print(data)
def Crawl_JSON():
ua = UserAgent()
headers={
'User-Agent':ua.random,
'Host':'m.maoyan.com',
'Referer':'http://m.maoyan.com/movie/1217236/comments?_v_=yes'
}
#猫眼电影短评接口
#因为猫眼的数据是AJAX类型的 里面的offset是改变的 第一次是0 第二次15 第三次是30 以此类推 这个page 相当于100/15然后循环
#可以自信观察猫眼AJAX数据请求参数 就会知道了
page=100
u=0
for i in range(page):
try:
offset=u
startTime = '2018-10-11'
comment_api = 'http://m.maoyan.com/mmdb/comments/movie/1217236.json?_v_=yes&offset={0}&startTime={1}%2021%3A09%3A31'.format(offset,startTime)
#发送get请求
response_coment=requests.get(url=comment_api,headers=headers)
json_comment=response_coment.text
json_comments=json.loads(json_comment)
parse_json(json_comments)
u+=15
except Exception as e:
print('出现错误:',e.args)
parse_json(Crawl_JSON())
Python
1
https://gitee.com/bqb/python_reptilian.git
git@gitee.com:bqb/python_reptilian.git
bqb
python_reptilian
Python爬虫
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891