閱讀823 返回首頁    go 阿裏雲 go 技術社區[雲棲]


python獲取央視節目信息

# -*- coding: utf-8 -*-  
#---------------------------------------  
#   程序:cctv節目表抓取  
#   作者:lqf  
#   日期:2013-08-09  
#   語言:Python 2.7  
#   功能:抓取央視的節目列表信息
#---------------------------------------  
   
import string  
import urllib2  
import re  
import sys

#------主程序-----
channel=['cctv1','cctv6','cctv10','cctv12','cctv13']
url = 'https://tv.cntv.cn/live/cctv1?date=2013-08-09'
content = urllib2.urlopen(url).read()
#網站是utf-8編碼,需要轉換成本地係統編碼格式才能在控製台顯示
typeEncode=sys.getfilesystemencoding()
content=content.decode('UTF-8').encode(typeEncode)
#獲取節目列表
playlist2=re.findall(r'.*?starttime="(.*?)".*?endtime="(.*?)".*?title="(.*?)" ?',content,re.S)
if playlist2:
    for x in playlist2:
        print x[2].decode(typeEncode)
        print u'開始時間:'+x[0][-4:-2]+u'點'+x[0][-2:]+u'分'+u' 結束時間:'+x[1][-4:-2]+u'點'+x[1][-2:]+u'分'
        print


如果要獲取其他頻道和日期的節目的話,隻要更改url就行了

最後更新:2017-04-03 16:48:54

  上一篇:go 【C大事】第四講:重複代碼封裝函數的思想
  下一篇:go Linux中關機命令詳解