尝试解析托管在网站上的xml文件中的信息。我正在为xbmc制作一个电视插件,我的问题是信息全部在页面上,我只想解析像第1季一样的部分!它只在一个地方显示第一季,然后在第二季下面的所有剧集然后在第二季。我不知道怎么写它的代码类型只能在第一季中点击第一季!以下是我的进展:
if type == 'tv_seasons':
match=re.compile('<Season no="(.+?)">').findall(content)
for seasonnumber in match:
item_url = new_url
item_title = 'Season ' + seasonnumber
item_id = common.CreateIdFromString(title + ' ' + item_title)
self.AddContent(list, indexer, common.mode_Content, item_title, item_id, 'tv_episodes', url=item_url, name=name, season=seasonnumber)
elif type == 'tv_episodes':
from entertainment.net import Net
net = Net()
content2 = net.http_GET(url).content
match=re.compile('<episode><epnum>.+?</epnum><seasonnum>(.+?)</seasonnum>.+?<link>(.+?)</link><title>(.+?)</title>').findall(content2)
for item_v_id_2, link_url, item_title in match:
item_v_id_2 = str(int(item_v_id_2))
item_url = link_url
item_id = common.CreateIdFromString(name + '_season_' + season + '_episode_' + item_v_id_2)
self.AddContent(list, indexer, common.mode_File_Hosts, item_title, item_id, type, url=item_url, name=name, season=season, episode=item_v_id_2)
所以现在我正在使用它,但仍然没有为我工作。
tree2 = ET.parse(urllib.urlopen(url))
root2 = tree2.getroot()
seasonnum = root2.findall("Show/Episodelist/Season[@no='%s']/episode/seasonnum" % season)
seasonnumtext = seasonnum.text
title = root2.findall("Show/Episodelist/Season[@no='%s']/episode/title" % season)
item_title = title.text
item_v_id_2 = str(int(seasonnumtext))
item_url = url
item_id = common.CreateIdFromString(name + '_season_' + season + '_episode_' + item_v_id_2)
self.AddContent(list, indexer, common.mode_File_Hosts, item_title, item_id, type, url=item_url, name=name, season=season, episode=item_v_id_2)