how to use python xml.etree.ElementTree to parse eBay API response?

倖福魔咒の 提交于 2019-12-03 16:40:34

You can use ElementTree. If you want to get the items you can use findall and the path to the items, then iterate over the list of items:

items = root.findall(namespace+'searchResult/'+namespace+'item')
for item in items: 
     item.find(namespace+'itemId').text
     item.find(namespace+'title').text

To get directly to the first itemId from the root:

root.find(namespace+'searchResult/'+namespace+'item/'+namespace+'itemId')

Basically, the find method uses XPath to retrieve elements more than one level below the subelements. See also Effbot's explanation of XPath support in ElementTree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!