0

尝试从托管在站点上的 xml 文件中解析信息。我正在为 xbmc 制作一个电视插件,我的问题是信息都在页面上,我只想解析第 1 季的所有部分!它只在一个位置显示第 1 季,然后在第 2 季显示它下面的所有剧集。我不知道如何编写这种代码类型,如果点击第 1 季,只显示第 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)
4

1 回答 1

2

I would recommend using Python XML Parser. You can then traverse the XML tree in a similar manner to Python dictionaries and lists.

于 2014-02-19T18:51:52.203 回答