How to parse XML by using python
<p>I want to parse this url to get the text of \Roman\ </p>

<p><a href="http://jlp.yahooapis.jp/FuriganaService/V1/furigana?appid=dj0zaiZpPU5TV0Zwcm1vaFpIcCZzPWNvbnN1bWVyc2VjcmV0Jng9YTk-&amp;grade=1&amp;sentence=%E7%A7%81%E3%81%AF%E5%AD%A6%E7%94%9F%E3%81%A7%E3%81%99" rel="nofollow">http://jlp.yahooapis.jp/FuriganaService/V1/furigana?appid=dj0zaiZpPU5TV0Zwcm1vaFpIcCZzPWNvbnN1bWVyc2VjcmV0Jng9YTk-&amp;grade=1&amp;sentence=ç§ã¯å­¦çã§ã</a></p>

<p><a href="http://i.stack.imgur.com/9CHnt.png" rel="nofollow"><img src="http://i.stack.imgur.com/9CHnt.png" alt="enter image description here"></a></p>

<pre><code>import urllib
import xml.etree.ElementTree as ET

url = 'http://jlp.yahooapis.jp/FuriganaService/V1/furigana?appid=dj0zaiZpPU5TV0Zwcm1vaFpIcCZzPWNvbnN1bWVyc2VjcmV0Jng9YTk-&amp;grade=1&amp;sentence=ç§ã¯å­¦çã§ã'
uh = urllib.urlopen(url)
data = uh.read()
tree = ET.fromstring(data)
counts = tree.findall('.//Word')

for count in counts         
    print count.get('Roman')
</code></pre>

<p>But it didn't work.</p>

<p>I recently ran into a similar issue to this. It was because I was using an older version of the xml.etree package and to workaround that issue I had to create a loop for each level of the XML structure. For example:</p>

<pre><code>import urllib
import xml.etree.ElementTree as ET

url = 'http://jlp.yahooapis.jp/FuriganaService/V1/furigana?appid=dj0zaiZpPU5TV0Zwcm1vaFpIcCZzPWNvbnN1bWVyc2VjcmV0Jng9YTk-&amp;grade=1&amp;sentence=ç§ã¯å­¦çã§ã'
uh = urllib.urlopen(url)
data = uh.read()
tree = ET.fromstring(data)
counts = tree.findall('.//Word')

for result in tree.findall('Result'):
    for wordlist in result.findall('WordList'):
        for word in wordlist.findall('Word'):         
            print(word.get('Roman'))
</code></pre>

<p>Edit:</p>

<p>With the suggestion from @omu_negru I was able to get this working. There was another issue, when getting the text for "Roman" you were using the "get" method which is used to get attributes of the tag. Using the "text" attribute of the element you can get the text between the opening and closing tags. Also, if there is no 'Roman' tag, you'll get a None object and won't be able to get an attribute on None.</p>

<pre><code># encoding: utf-8
import urllib
import xml.etree.ElementTree as ET

url = 'http://jlp.yahooapis.jp/FuriganaService/V1/furigana?appid=dj0zaiZpPU5TV0Zwcm1vaFpIcCZzPWNvbnN1bWVyc2VjcmV0Jng9YTk-&amp;grade=1&amp;sentence=ç§ã¯å­¦çã§ã'
uh = urllib.urlopen(url)
data = uh.read()
tree = ET.fromstring(data)
ns = '{urn:yahoo:jp:jlp:FuriganaService}'
counts = tree.findall('.//%sWord' % ns)

for count in counts:
    roman = count.find('%sRoman' % ns)
    if roman is None:
        print 'Not found'
    else:
        print roman.text
</code></pre>

python xml parsing