GAE/Pythonで、Amazon Product Advertising APIを使い、商品を検索してみる
GAEということで、なるべく標準の物を使った方が良いと思い、
返ってきたxmlの解析はElementTreeを使うことにしました。
使い方は、こちらを参考にさせていただきました
http://blog.livedoor.jp/yawamen/archives/51520512.html
bottlenoseを使うことにしました。
使い方は、こちらを参考にさせていただきました。
http://www.ninxit.com/blog/2011/06/09/python-amazon-product-advertising-api/
from xml.etree.ElementTree import *
import bottlenose
AWS_KEY = ''
SECRET_KEY = ''
ASSOCIATE_TAG = '-22'
class TestAmazonSearchHandler(webapp.RequestHandler):
def get(self):
amazon = bottlenose.Amazon(AWS_KEY, SECRET_KEY,ASSOCIATE_TAG)
result = amazon.ItemSearch(Keywords=u'jobs', SearchIndex='Books', ItemPage='1', ResponseGroup='Small')
root = fromstring(result)
count = 0
xmlns = '{http://webservices.amazon.com/AWSECommerceService/2011-08-01}'
Items = root.find(xmlns+'Items')
if Items:
for item in Items.findall(xmlns +'Item'):
print "-"
print item.findtext(xmlns+'DetailPageURL')
print "-"
itemAttributes = item.find(xmlns+'ItemAttributes')
if itemAttributes:
#print itemAttributes.findtext(xmlns+'Author') #authorは本によって無い場合があったのでひとまず外した
print itemAttributes.findtext(xmlns+'Title')
print itemAttributes.findtext(xmlns+'Manufacturer')
print itemAttributes.findtext(xmlns+'ProductGroup')
count += 1
print str(count)
print "-----"
※↑すみません、<p>タグがどうやっても入ってしまうので、除いてご利用いただければと思いますm(_ _)m
これで、こちらの環境では・・
-
-
スティーブ・ジョブズ I/
講談社/
Book
1