【python|bilibili番剧评分爬虫】python选修课学习中练手写的,主要就是查询bilibili提供得api
# -*- coding:utf-8 -*-import requests
import json
import csv
import sys#将windows系统默认语言从gbk-2312设置为utf-8
reload(sys)
sys.setdefaultencoding('utf-8')def rating(bangumi_id):
payload = {'callback': 'seasonListCallback'}
response = requests.get('https://bangumi.bilibili.com/jsonp/seasoninfo/{0}.ver'.format(bangumi_id), params=payload)
data = https://www.it610.com/article/json.loads(response.text[19:-2])
try:
season_id = int(data['result']['season_id'])
title = '{0}'.format(data['result']['media']['title'])
score = float(data['result']['media']['rating']['score'])
count = int(data['result']['media']['rating']['count'])
is_finish = int(data['result']['is_finish'])
try:
writer.writerow([season_id, title, score, count, is_finish])
except:
pass
except KeyError:
try:
season_id = int(data['result']['season_id'])
title = '{0}'.format(data['result']['title'])
score=float(0)
count=int(0)
is_finish = int(data['result']['is_finish'])
try:
writer.writerow([season_id, title, score, count, is_finish])
except:
pass
except:
return None
return None
if __name__ == '__main__':
with open('bangumi.csv', 'wb+') as csv_file:
writer = csv.writer(csv_file, delimiter=',')
writer.writerow(['序号','名称', '评分(默认0分)', '评分人数(人数不足为0人)', '是否完结(1:表示已完结)'])
for i in range(7000):
rating(i)
整理结果csv https://pan.baidu.com/s/1jHX2fJ4
转载于:https://www.cnblogs.com/kagari/p/8207233.html
推荐阅读
- 推荐系统论文进阶|CTR预估 论文精读(十一)--Deep Interest Evolution Network(DIEN)
- 接口|axios接口报错-参数类型错误解决
- Python专栏|数据分析的常规流程
- Python|Win10下 Python开发环境搭建(PyCharm + Anaconda) && 环境变量配置 && 常用工具安装配置
- Python绘制小红花
- Pytorch学习|sklearn-SVM 模型保存、交叉验证与网格搜索
- OpenCV|OpenCV-Python实战(18)——深度学习简介与入门示例
- python|8. 文件系统——文件的删除、移动、复制过程以及链接文件
- 爬虫|若想拿下爬虫大单,怎能不会逆向爬虫,价值过万的逆向爬虫教程限时分享
- 分布式|《Python3网络爬虫开发实战(第二版)》内容介绍