0

サイトでホストされている xml ファイルから情報を解析しようとしています。私は xbmc 用のテレビ アドオンを作成しています。私の問題は、情報がすべてページ上にあり、シーズン 1 のすべてのようなセクションでのみ解析したいということです! シーズン 1 を 1 つの場所に表示し、その下のすべてのエピソードをシーズン 2 に表示するだけです。以下は私が行っていることです:

    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

Python XML Parserの使用をお勧めします。その後、Python の辞書やリストと同様の方法で XML ツリーをトラバースできます。

于 2014-02-19T18:51:52.203 に答える