亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術(shù)文章
文章詳情頁

Python爬蟲爬取電影票房數(shù)據(jù)及圖表展示操作示例

瀏覽:93日期:2022-07-31 18:50:36

本文實例講述了Python爬蟲爬取電影票房數(shù)據(jù)及圖表展示操作。分享給大家供大家參考,具體如下:

爬蟲電影歷史票房排行榜 http://www.cbooo.cn/BoxOffice/getInland?pIndex=1&t=0

Python爬取歷史電影票房紀錄 解析Json數(shù)據(jù) 橫向條形圖展示 面向?qū)ο笏枷?p>導入相關(guān)庫

import requestsimport refrom matplotlib import pyplot as pltfrom matplotlib import font_managerimport 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)

調(diào)用類并展示

if __name__ == ’__main__’: dy_order = DYOrder(1) # type 1 豎向條形圖 2 橫向 dy_order.to_run(2)

Python爬蟲爬取電影票房數(shù)據(jù)及圖表展示操作示例Python爬蟲爬取電影票房數(shù)據(jù)及圖表展示操作示例

更多關(guān)于Python相關(guān)內(nèi)容可查看本站專題:《Python Socket編程技巧總結(jié)》、《Python正則表達式用法總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》

希望本文所述對大家Python程序設(shè)計有所幫助。

標簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: a级国产乱理论片在线观看ai | 亚洲国产精品ⅴa在线观看 亚洲国产精品aaa一区 | 日韩黄色在线视频 | 国产香蕉在线视频 | 午夜激情福利网 | 日本不卡中文字幕 | 在线观看91香蕉国产免费 | 国产乱子精品免费视观看片 | 公又粗又长又大又深好爽日本 | 99久久精品免费 | 久久精品成人免费网站 | 快射影院 | 在线日韩视频 | 免费国产一区二区在免费观看 | 日韩欧美一区二区三区在线视频 | 大香香蕉 | 国产午夜精品久久久久免费视小说 | 亚洲涩涩| 成人爽爽激情在线观看 | 精品国产看高清国产毛片 | 免费a在线 | 毛片在线播放观看日本 | 麻豆视传媒一区二区三区 | 久久国产中文字幕 | 中日韩黄色大片 | 黄色大片网站 | 免费看成人国产一区二区三区 | 国产美女精品在线观看 | 91黑丝国产线观看免费 | 你懂的在线免费视频 | 国语对白清晰好大好白在线 | 爱爱永久免费视频网站 | 理论片我不卡在线观看 | 亚洲麻豆精品果冻传媒 | 日韩一区二区三区四区五区 | 久久精品国产74国产 | 达达兔午夜国产精品 | 特黄特黄aaaa级毛片免费看 | 久久视频精品a线视频在线观看 | 国产大片中文字幕在线观看 | 日产国产欧美韩国在线 |