xml.etree.ElementTree を使用して、eBay 検索 API、findItemsByProduct からの応答を解析しようとしています。長い試行錯誤の後、いくつかのデータを出力する次のコードを思いつきました。
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' \
+ '&SERVICE-VERSION=1.0.0' \
+ '&GLOBAL-ID=EBAY-DE' \
+ '&SECURITY-APPNAME=' + appID \
+ '&RESPONSE-DATA-FORMAT=XML' \
+ '&REST-PAYLOAD' \
+ '&productId.@type=ISBN&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
しかし、それはあまりエレガントではないようです。すべての属性をループせずに「itemId」と「title」を取得し、それが必要なものかどうかを確認するにはどうすればよいですか? .get(namespace + 'itemId')
and .find(namespace + 'itemId')
and などを使用してみ.attrib.get(namespace + 'itemId')
ましたが、実際には何も機能しませんでした。
このAPIのPythonラッパーを使用してこれを行う方法を教えてもらえますか? easyBay、ebay-sdk-python、およびpyeBayを見ましたが、それらのいずれも自分のやりたいことを実行させることができませんでした。これに使用する価値のある eBay python API はありますか?