這篇文章主要為大家展示了“Python如何爬取電影票房數(shù)據(jù)”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學習一下“Python如何爬取電影票房數(shù)據(jù)”這篇文章吧。
成都創(chuàng)新互聯(lián)公司是一家專業(yè)提供廣西企業(yè)網(wǎng)站建設,專注與成都網(wǎng)站建設、成都網(wǎng)站制作、成都h5網(wǎng)站建設、小程序制作等業(yè)務。10年已為廣西眾多企業(yè)、政府機構(gòu)等服務。創(chuàng)新互聯(lián)專業(yè)的建站公司優(yōu)惠進行中。爬蟲電影歷史票房排行榜 http://www.cbooo.cn/BoxOffice/getInland?pIndex=1&t=0
Python爬取歷史電影票房紀錄
解析Json數(shù)據(jù)
橫向條形圖展示
面向?qū)ο笏枷?/p>
導入相關(guān)庫
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)調(diào)用類并展示
if __name__ == '__main__': dy_order = DYOrder(1) # type 1 豎向條形圖 2 橫向 dy_order.to_run(2)


以上是“Python如何爬取電影票房數(shù)據(jù)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學習更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站設計公司行業(yè)資訊頻道!
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
分享標題:Python如何爬取電影票房數(shù)據(jù)-創(chuàng)新互聯(lián)
轉(zhuǎn)載源于:http://chinadenli.net/article40/ccjseo.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供標簽優(yōu)化、App開發(fā)、網(wǎng)站內(nèi)鏈、營銷型網(wǎng)站建設、靜態(tài)網(wǎng)站、品牌網(wǎng)站設計
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容