Search code examples
pythonxmlxpathxbmc

Issue with xpath for python


Very new with elementtree so i'm trying to parse xml file for tv addon for xbmc. Below is the code that i'm having issue with. I think my xpath is not correct and placeholder is not working on the the attribute!

This is the xml file i'm workig with - http://services.tvrage.com/myfeeds/episode_list.php?key=ag6txjP0RH4m0c8sZk2j&sid=2930

    seasonnum = root2.findall("/Show/Episodelist/Season[@no='%s']/episode/seasonnum" % (season))


        import xml.etree.ElementTree as ET
        import urllib            
        tree2 = ET.parse(urllib.urlopen(url))
        root2 = tree2.getroot()
        seasonnum = tree2.findall("./Episodelist/Season[@no='%s']/episode/seasonnum" % '1')
        print seasonnum

SyntaxError: expected path separator ([) is what i get


Solution

  •     import xml.etree.ElementTree as ET
        import urllib
        content = urllib.urlopen(url).read()
        tree2 = ET.fromstring(content)
        tvrage_seasons = tree2.findall('.//Season' )
    

    Had to work it like this as for some reason in xbmc Elementtree there must be an error or something to not make it work. But this worked out for me!