Python xml解析スクリプトを使用して、wolframapiの出力を取得しようとしています。これが私のスクリプトです:
import urllib
import urllib.request
import xml.etree.ElementTree as ET
xml_data=urllib.request.urlopen("http://api.wolframalpha.com/v2/query?input=sqrt+2&appid=APLTT9-9WG78GYE65").read()
root = ET.fromstring(xml_data)
for child in root:
print (child.get("title"))
print (child.attrib)
コードのタイトル部分にあるすべての属性を取得しているだけですが、それは始まりです。
出力の抜粋は次のとおりです。
<pod title="Input" scanner="Identity" id="Input" position="100" error="false" numsubpods="1">
<subpod title="">
<plaintext>sqrt(2)</plaintext>
タグにあるものだけを印刷するようにしようとしています。誰かがそれを得るためにコードを編集する方法を知っていますか?