我正在使用我的python脚本从我自己的xml文件中打印字符串列表。
我正在尝试找出如何从程序通道标记中打印字符串列表,以获取start =“”和stop =“”标记中的格式。当我想要获取格式和标题列表时,我只会获得您可以在此处看到的频道列表:
0115:00:58 T:3316 NOTICE: 101 ABC FAMILY
0215:00:58 T:3316 NOTICE: 102 CBS
0315:00:58 T:3316 NOTICE: 103 CNN USA
0415:00:58 T:3316 NOTICE: 105 ESPN USA
0515:00:58 T:3316 NOTICE: 106 Fox News
0615:00:58 T:3316 NOTICE: 107 Animal Planet
0715:00:58 T:3316 NOTICE: 108 USA Network
0815:00:58 T:3316 NOTICE: 110 SPIKE
0915:00:58 T:3316 NOTICE: 111 BRAVO USA
1015:00:58 T:3316 NOTICE: 112 BRAVO1
1115:00:58 T:3316 NOTICE: 113 BRAVO2
1215:00:58 T:3316 NOTICE: 114 BRAVO3
1315:00:58 T:3316 NOTICE: 115 BRAVO4
1415:00:58 T:3316 NOTICE: 116 BRAVO5
1515:00:58 T:3316 NOTICE: 117 BRAVO6
1615:00:58 T:3316 NOTICE: 118 BRAVO7
这是xml:
<tv generator-info-name="www.mysite.com/xmltv">
<channel id="101 ABC FAMILY">
<display-name>101 ABC FAMILY</display-name>
<programme channel="101 ABC FAMILY" start="" stop="20140517070000">
<title lang="en">The Karate Kid Part III</title>
<sub-title lang="en"></sub-title>
<desc lang="en"></desc>
<category lang="en"></category>
</programme>
<programme channel="101 ABC FAMILY"start="20140517070000" stop="20140517093000">
<title lang="en">The Karate Kid</title>
<sub-title lang="en"></sub-title>
<desc lang="en"></desc>
<category lang="en"></category>
</programme>
</channel>
以下是代码:
#DOWNLOAD THE XML SOURCE HERE
url = ADDON.getSetting('allchannels.url')
req = urllib2.Request(url)
response = urllib2.urlopen(req)
data = response.read()
response.close()
profilePath =xbmc.translatePath(os.path.join('
special://userdata/addon_data/script.tvguide', ''))
if os.path.exists(profilePath):
profilePath = profilePath + 'source.db'
con = database.connect(profilePath)
cur = con.cursor()
cur.execute('CREATE TABLE programs(id TEXT, channel TEXT, title TEXT,
start_date TIMESTAMP, end_date TIMESTAMP, description TEXT)')
con.commit()
con.close
tv_elem =ElementTree.parse(StringIO.StringIO(data)).getroot()
profilePath =xbmc.translatePath(os.path.join('special://userdata/addon_data/script.tvguide', ''))
profilePath = profilePath + 'source.db'
con = database.connect(profilePath)
cur = con.cursor()
channels = OrderedDict()
for elem in tv_elem.getchildren():
if elem.tag == 'channel':
channels[elem.attrib['id']] =self.load_channel(elem)
elif elem.tag == 'programme':
# get channel
channel =channels[elem.attrib['programme']]
channel =channels[elem.attrib['title']]
# load program in channel
channel.get_programs().append(self.load_programme(elem))
for channel_key in channels:
channel = channels[channel_key]
display_name =channel.get_display_name()
print channel.get_display_name()
您能否帮我解释如何从标题标签中的start =“”和stop =“”标签打印格式列表?