Python獲取央視節(jié)目單的實(shí)現(xiàn)代碼
本文實(shí)例講述了Python獲取央視節(jié)目單的方法。分享給大家供大家參考。具體如下:
#! /usr/bin/python # -*- coding: utf-8 -*- import urllib,re,unicodedata,string,sys from time import strftime,localtime channel={"1":"CCTV-1","2":"CCTV-2","3":"CCTV-3","4":"CCTV-4亞洲", "5":"CCTV-4歐洲","6":"CCTV-4美洲","7":"CCTV-5","8":"CCTV-6", "9":"CCTV-7","10":"CCTV-8","11":"CCTV-9","12":"CCTV-10", "13":"CCTV-11","14":"CCTV-12","15":"CCTV新聞","16":"CCTV少兒", "17":"CCTV音樂","18":"CCTV_E","19":"CCTV-F","20":"CCTV-高清"} if __name__=="__main__": print "@@" print "@@ 你可以在命令行后輸入數(shù)字(1-20)來選擇頻道 " print "@@ 通過在命令行后鍵入help獲取頻道列表" print "@@" if len(sys.argv)==1: Select="8" else: if sys.argv[1]=="help": for i in range(len(channel)): print "%3d : %11s" % (i+1, channel["%s" % (i+1)]), if(i%4 == 3): print "" sys.exit(0) if string.atoi(sys.argv[1])>20 or string.atoi(sys.argv[1])<=0: print "Out of Range. Please Select 1-20." sys.exit(0) else: Select=sys.argv[1] print '正在獲取節(jié)目單,請(qǐng)稍后...' date=strftime('%Y%m%d',localtime()) response = urllib.urlopen("http://tv.cctv.com/soushi/28/0"+Select+"/"+date+".shtml") Result=response.read() #list=re.findall(r"<div class='tlb_right'><div class='l'>(.+?)<script",Result,re.S) list=re.findall(r"上午節(jié)目(.+?)<script",Result,re.S) list2=re.findall(r"<li>(.+?)</li>",list[0],re.S) morning=[] afternoon=[] listnum=0 for i in range(len(list2)): i=re.sub('<.+?>','',list2[i]) if string.atoi(i[:2])>=12: #將上午的節(jié)目于下午的節(jié)目分開 afternoon.append(i) else: morning.append(i) if len(morning)>len(afternoon): listnum=len(morning) else: listnum=len(afternoon) print "-"*80, print " "*13+"上午節(jié)目"+" "*26+"下午節(jié)目" print " "*14+"========"+" "*26+"========" for i in range(listnum): if(i<len(morning)): print "%-4s %-29s" %(morning[i][:5],morning[i][5:]), else: print " "*35, if(i<len(afternoon)): print "%-4s %-30s" %(afternoon[i][:5],afternoon[i][5:]) else: print " "*37 print "-"*80, print " "*24,strftime("%Y年%m月%d日"), print "%s 節(jié)目單" %channel[Select]
希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
相關(guān)文章
python點(diǎn)擊鼠標(biāo)獲取坐標(biāo)(Graphics)
這篇文章主要為大家詳細(xì)介紹了python點(diǎn)擊鼠標(biāo)獲取坐標(biāo),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-08-08matplotlib.pyplot畫圖 圖片的二進(jìn)制流的獲取方法
今天小編就為大家分享一篇matplotlib.pyplot畫圖 圖片的二進(jìn)制流的獲取方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-05-05matplotlib之pyplot模塊實(shí)現(xiàn)添加子圖subplot的使用
這篇文章主要介紹了matplotlib之pyplot模塊實(shí)現(xiàn)添加子圖subplot的使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04python Matplotlib基礎(chǔ)--如何添加文本和標(biāo)注
這篇文章主要介紹了python Matplotlib基礎(chǔ)--如何添加文本和標(biāo)注,幫助大家更好的利用Matplotlib繪制圖表,感興趣的朋友可以了解下2021-01-01Django ModelSerializer實(shí)現(xiàn)自定義驗(yàn)證的使用示例
本文主要介紹了Django ModelSerializer實(shí)現(xiàn)自定義驗(yàn)證的使用示例,多種字段驗(yàn)證器幫助開發(fā)者確保數(shù)據(jù)的完整性和準(zhǔn)確性,具有一定的參考價(jià)值,感興趣的可以了解一下2023-11-11python3 QT5 端口轉(zhuǎn)發(fā)工具兩種場景分析
這篇文章主要介紹了python3 QT5 端口轉(zhuǎn)發(fā)工具,功能是打開本機(jī)端口,映射到指定IP的端口,接下來通過兩種場景給大家詳細(xì)介紹,感興趣的朋友一起看看吧2022-01-01