阅读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中关机命令详解