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 = 'http://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'class="play".*?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就行了
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值