In this paper, we describe how Python obtains the CCTV program. Share to everyone for your reference. Specific as follows:
#! /usr/bin/python #-*-coding:utf-8-*-import Urllib,re,unicodedata,string,sys from time import Strftime,localtime Channe l={"1": "CCTV-1", "2": "CCTV-2", "3": "CCTV-3", "4": "CCTV-4 Asia", "5": "CCTV-4 Europe", "6": "CCTV-4 Americas", "7": "CCTV-5", "8": " CCTV-6 "," 9 ":" CCTV-7 "," Ten ":" CCTV-8 "," one ":" CCTV-9 "," one ":" CCTV-10 "," All ":" CCTV-11 "," All ":" CCTV-12 "," All ":" CCTV News "," "CCTV children", "" ":" CCTV Music "," "": "Cctv_e", "" ":" Cctv-f "," ":" cctv-HD "} If __name__==" __main__ ": print" @@ "print" @ @ You can enter the number (1-20) after the command line to select the channel "print" @@ 通过 typing help at the command line to get the channel list "print" @@ 通过 if Len (sys.argv) ==1:select= "8" Else: If sys.argv[1]== "Help": For I in range (len): 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 ' is getting the program, please later ... ' 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 "(. +?)