我想使用python xml解析腳本獲取wolfram api的輸出。這是我的腳本:Wolfram Api的Python Xml解析
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>
我試圖讓它只打印出什麼是在標籤。有誰知道如何編輯代碼來獲取?
所以你想要'sqrt(2)'打印? – 2013-03-15 21:13:43