我从请求中获取XML响应,我需要解析并找到特定节点值。
<?xml version="1.0" encoding="UTF-8"?>
<response>
<statusCode>200</statusCode>
<statusText>Ok</statusText>
<data>
<testId>161115_16_J1G</testId>
<ownerKey></ownerKey>
<xmlUrl>http://www.webpagetest.org/xmlResult/161115_16_J1G/</xmlUrl>
<userUrl>http://www.webpagetest.org/result/161115_16_J1G/</userUrl>
<summaryCSV>http://www.webpagetest.org/result/161115_16_J1G/page_data.csv
</summaryCSV>
<detailCSV>http://www.webpagetest.org/result/161115_16_J1G/requests.csv
</detailCSV>
</data>
</response>
response=urllib2.urlopen("url")
print(response)
xml=ET.fromstring(response)
root = xml.getroot()
for child in root:
print child.tag, child.attrib
output
状态码:200 statustetxt:OK 数据:\ n 没有得到剩下的价值
答案 0 :(得分:0)
child=tree.findall("/data/")
for x in child:
print x.tag,x.text
它对我有用