没有合适的资源?快使用搜索试试~ 我知道了~
首页Python爬虫爬取电影票房数据及图表展示操作示例
Python爬虫爬取电影票房数据及图表展示操作示例
5星 · 超过95%的资源 32 下载量 66 浏览量
更新于2023-05-04
评论 3
收藏 186KB PDF 举报
本文实例讲述了Python爬虫爬取电影票房数据及图表展示操作。分享给大家供大家参考,具体如下: 爬虫电影历史票房排行榜 http://www.cbooo.cn/BoxOffice/getInland?pIndex=1&t=0 Python爬取历史电影票房纪录 解析Json数据 横向条形图展示 面向对象思想 导入相关库 import requests import re from matplotlib import pyplot as plt from matplotlib import font_manager import json 类代码部分 class DYOrde
资源详情
资源评论
资源推荐
Python爬虫爬取电影票房数据及图表展示操作示例爬虫爬取电影票房数据及图表展示操作示例
本文实例讲述了Python爬虫爬取电影票房数据及图表展示操作。分享给大家供大家参考,具体如下:
爬虫电影历史票房排行榜 http://www.cbooo.cn/BoxOffice/getInland?pIndex=1&t=0
Python爬取历史电影票房纪录
解析Json数据
横向条形图展示
面向对象思想
导入相关库导入相关库
import requests
import re
from matplotlib import pyplot as plt
from matplotlib import font_manager
import json
类代码部分类代码部分
class DYOrder(object):
#初始化
def __init__(self,page=1):
self.url = 'http://www.cbooo.cn/BoxOffice/getInland?pIndex={}&t=0'.format(page)
self.headers = {'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36'}
#请求
def __to_request(self):
response = requests.get(url=self.url,headers=self.headers)
return self.__to_parse(response.content.decode('utf-8'))
#解析
def __to_parse(self,html):
#返回为JSON字符串
#首先将字符串反序列化为JSON对象
my_json = json.loads(html)
return my_json
#图表展示
def __to_show(self,data,show_type):
x = [] y = [] for value in data:
x.append(value['MovieName'])
y.append(int(value['BoxOffice']))
my_font = font_manager.FontProperties(fname='/System/Library/Fonts/PingFang.ttc',size=18)
if show_type == 1:
plt.figure(figsize=(20,8),dpi=80)
rects = plt.bar(range(len(x)),[float(i) for i in y],width=0.5,color='red')
plt.xticks(range(len(x)),x,fontproperties=my_font,rotation=60)
plt.xlabel('名称',rotation=60,color='blue',fontproperties=my_font)
plt.ylabel('票房/万',rotation=60,color='blue',fontproperties=my_font)
for rect in rects:
height = rect.get_height()
plt.text(rect.get_x() + rect.get_width()/2,height+0.4,str(height),ha='center',rotation=30)
else:
# 横向 plt.barh(y,x)
plt.figure(figsize=(15,13),dpi=80)
rects = plt.barh(range(len(x)),y,height=0.8,color='orange')
plt.yticks(range(len(x)),x,fontproperties=my_font,rotation=30)
plt.ylabel('名称',rotation=0,color='blue',fontproperties=my_font)
plt.xlabel('票房/万',rotation=60,color='blue',fontproperties=my_font)
for rect in rects:
width = rect.get_width()
plt.text(width, rect.get_y()+0.3/2,str(width),va='center',rotation=30)
plt.grid(alpha=0.4)
plt.title('中国电影历史票房排行榜',color='red',size=18,fontproperties=my_font)
plt.show()
#所有操作
def to_run(self,show_type=1):
result = self.__to_request()
self.__to_show(result,show_type)
调用类并展示调用类并展示
if __name__ == '__main__':
dy_order = DYOrder(1)
# type 1 竖向条形图 2 横向
dy_order.to_run(2)
weixin_38699352
- 粉丝: 7
- 资源: 920
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论5