电影票房的实时统计

xiaoxiao2021-02-28  295

# -*- coding: utf-8 -*- import urllib2 import re import os BOR_amount=0.0 url='http://58921.com/' req = urllib2.Request(url, headers={'User-Agent' : "Magic Browser"}) webpage= urllib2.urlopen(req) strw=webpage.read() s=strw.find("电影名称</th><th>总场次/占比") e=strw[s:].find("各平台场次存在重叠,实时与预计票房为程序自行计算,仅供参考") strw_tab=strw[s:s+e] # 14. #print strw_tab m=[] m=re. findall( r'<tr class="[a-z]{3,4}"><td><a href="/film/[0-9]+/boxoffice" title=.+</tr>',strw_tab) # 15. print '----------------------' print m if not m: os.exit() for t in m: ss=[] ss=re.findall(r'(\d+[\.|/]?\d*[\.]?\d*[%]*[^\x00-\xff]*)',t) # 16. # print ss if ss: BOR_amount+= float(ss[-3]) #对 实时的票房 进行迭代累加 #如果 票房数据有缺失值 就会报错,需要注意 # print BOR_amount else: print "error" print "票房总额是: "+str(BOR_amount)+"万元"
转载请注明原文地址: https://www.6miu.com/read-994938.html

最新回复(0)