GAE/Pythonで、Amazon Product Advertising APIを使い、商品を検索してみる

GAEということで、なるべく標準の物を使った方が良いと思い、

返ってきたxmlの解析はElementTreeを使うことにしました。

使い方は、こちらを参考にさせていただきました

http://blog.livedoor.jp/yawamen/archives/51520512.html

amazon apiとのやりとりは、

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

これで、こちらの環境では・・

-

http://www.amazon.co.jp/%E3%82%B9%E3%83%86%E3%82%A3%E3%83%BC%E3%83%96%E3%83%BB%E3%82%B8%E3%83%A7%E3%83%96%E3%82%BA-I-%E3%82%A6%E3%82%A9%E3%83%AB%E3%82%BF%E3%83%BC%E3%83%BB%E3%82%A2%E3%82%A4%E3%82%B6%E3%83%83%E3%82%AF%E3%82%BD%E3%83%B3/dp/4062171260%3FSubscriptionId%3DAKIAJ7HHIWJRA6ZU54AA%26tag%3Dsuzukikuni-22%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D4062171260

-

スティーブ・ジョブズ I/

講談社/

Book

1