# -*- 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就行了