Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to use python xml.etree.ElementTree to parse eBay API response?
    primarykey
    data
    text
    <p>I am trying to use xml.etree.ElementTree to parse responses from eBay finding API, findItemsByProduct. After lengthy trial and error, I came up with this code which prints some data:</p> <pre><code>import urllib from xml.etree import ElementTree as ET appID = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' isbn = '3868731342' namespace = '{http://www.ebay.com/marketplace/search/v1/services}' url = 'http://svcs.ebay.com/services/search/FindingService/v1?' \ + 'OPERATION-NAME=findItemsByProduct' \ + '&amp;SERVICE-VERSION=1.0.0' \ + '&amp;GLOBAL-ID=EBAY-DE' \ + '&amp;SECURITY-APPNAME=' + appID \ + '&amp;RESPONSE-DATA-FORMAT=XML' \ + '&amp;REST-PAYLOAD' \ + '&amp;productId.@type=ISBN&amp;productId=' + isbn root = ET.parse(urllib.urlopen(url)).getroot() for parts in root: if parts.tag == (namespace + 'searchResult'): for item in list(parts): for a in list(item): if a.tag == (namespace + 'itemId'): print 'itemId: ' + a.text if a.tag == (namespace + 'title'): print 'title: ' + a.text </code></pre> <p>But that seems not very elegant, how can I get the 'itemId' and 'title' without looping over all attributes and checking if it is the one I want? I tried using things like <code>.get(namespace + 'itemId')</code> and <code>.find(namespace + 'itemId')</code> and <code>.attrib.get(namespace + 'itemId')</code> but nothing really worked.</p> <p>Can someone maybe show me how to do this using some python wrapper for this API? I saw <a href="http://pypi.python.org/pypi/easyBay" rel="nofollow">easyBay</a>, <a href="http://code.google.com/p/ebay-sdk-python/" rel="nofollow">ebay-sdk-python</a> and <a href="http://ebaydeveloper.typepad.com/pyebay.html" rel="nofollow">pyeBay</a> but I didn't manage to get any of them to do what I want. Is there any eBay python API which is worthwhile to use for this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload