成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

Python如何爬取電影票房數(shù)據(jù)-創(chuàng)新互聯(lián)

這篇文章主要為大家展示了“Python如何爬取電影票房數(shù)據(jù)”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“Python如何爬取電影票房數(shù)據(jù)”這篇文章吧。

成都創(chuàng)新互聯(lián)公司是一家專業(yè)提供廣西企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站建設(shè)、成都網(wǎng)站制作、成都h5網(wǎng)站建設(shè)、小程序制作等業(yè)務(wù)。10年已為廣西眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)的建站公司優(yōu)惠進(jìn)行中。

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

  1. Python爬取歷史電影票房紀(jì)錄

  2. 解析Json數(shù)據(jù)

  3. 橫向條形圖展示

  4. 面向?qū)ο笏枷?/p>

導(dǎo)入相關(guān)庫(kù)

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'}
  #請(qǐng)求
  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對(duì)象
    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('票房/萬(wàn)',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('票房/萬(wàn)',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('中國(guó)電影歷史票房排行榜',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ù)

以上是“Python如何爬取電影票房數(shù)據(jù)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站設(shè)計(jì)公司行業(yè)資訊頻道!

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

分享標(biāo)題:Python如何爬取電影票房數(shù)據(jù)-創(chuàng)新互聯(lián)
轉(zhuǎn)載源于:http://jinyejixie.com/article40/ccjseo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標(biāo)簽優(yōu)化、App開(kāi)發(fā)、網(wǎng)站內(nèi)鏈營(yíng)銷型網(wǎng)站建設(shè)、靜態(tài)網(wǎng)站、品牌網(wǎng)站設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

營(yíng)銷型網(wǎng)站建設(shè)
酉阳| 壶关县| 青海省| 瓦房店市| 孝感市| 广南县| 班戈县| 曲靖市| 攀枝花市| 美姑县| 湖南省| 偏关县| 弥渡县| 西华县| 阜康市| 闸北区| 佛山市| 加查县| 泰宁县| 西畴县| 和硕县| 卢湾区| 桂阳县| 开平市| 盈江县| 海南省| 工布江达县| 星子县| 陆河县| 宜黄县| 南昌市| 新闻| 康马县| 遂溪县| 枝江市| 瑞昌市| 宜宾县| 神农架林区| 荣昌县| 平阴县| 南投县|