Using XPath in ElementTree

后端 未结 5 1441
情话喂你
情话喂你 2020-11-30 00:51

My XML file looks like the following:




        
5条回答
  •  粉色の甜心
    2020-11-30 01:07

    Element tree uses namespaces so all the elements in your xml have name like {http://webservices.amazon.com/AWSECommerceService/2008-08-19}Items

    So make the search include the namespace e.g.

    search = '{http://webservices.amazon.com/AWSECommerceService/2008-08-19}Items/{http://webservices.amazon.com/AWSECommerceService/2008-08-19}Item/{http://webservices.amazon.com/AWSECommerceService/2008-08-19}ItemAttributes/{http://webservices.amazon.com/AWSECommerceService/2008-08-19}ListPrice/{http://webservices.amazon.com/AWSECommerceService/2008-08-19}Amount'
    element.findall( search )
    

    gives the element corresponding to 2260

提交回复
热议问题