本文整理汇总了Python中amazonproduct.api.API.item_lookup方法的典型用法代码示例。如果您正苦于以下问题:Python API.item_lookup方法的具体用法?Python API.item_lookup怎么用?Python API.item_lookup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类amazonproduct.api.API
的用法示例。
在下文中一共展示了API.item_lookup方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: amazon
# 需要导入模块: from amazonproduct.api import API [as 别名]
# 或者: from amazonproduct.api.API import item_lookup [as 别名]
def amazon(query):
api = API(AWS_KEY, SECRET_KEY, 'us', ASSOC_TAG)
similar_root = api.similarity_lookup('B0058U6DQC', ResponseGroup='Large')
product_root = api.item_lookup('B0058U6DQC', ResponseGroup='Large')
product_root = api.item_search(title='unicorn', ResponseGroup='Large')
more_products = api.item_search('Books', Publisher='Galileo Press')
#~ from lxml import etree
#~ print etree.tostring(root, pretty_print=True)
nspace = similar_root.nsmap.get(None, '')
similar_products = similar_root.xpath('//aws:Items/aws:Item',
namespaces={'aws' : nspace})
# more_products = product_root.xpath('//aws:Items/aws:Item',
# namespaces={'aws' : nspace})
return render_template("amazon.html", similar_products=similar_products, more_products = more_products, query=query)
示例2: parse
# 需要导入模块: from amazonproduct.api import API [as 别名]
# 或者: from amazonproduct.api.API import item_lookup [as 别名]
"""
Custom response parser using BeautifulSoup to parse the returned XML.
"""
def parse(self, fp):
soup = BeautifulSoup.BeautifulSoup(fp.read())
# parse errors
for error in soup.findAll('error'):
code = error.find('code').text
msg = error.find('message').text
raise AWSError(code, msg)
return soup
if __name__ == '__main__':
# Don't forget to create file ~/.amazon-product-api
# with your credentials (see docs for details)
api = API(locale='us', processor=SoupProcessor())
result = api.item_lookup('0718155157')
print result
# ...
# now do something with it!
示例3: minidom_response_parser
# 需要导入模块: from amazonproduct.api import API [as 别名]
# 或者: from amazonproduct.api.API import item_lookup [as 别名]
from xml.dom.minidom import parse
def minidom_response_parser(fp):
"""
Custom response parser using xml.dom.minidom.parse
instead of lxml.objectify.
"""
root = parse(fp)
# parse errors
for error in root.getElementsByTagName('Error'):
code = error.getElementsByTagName('Code')[0].firstChild.nodeValue
msg = error.getElementsByTagName('Message')[0].firstChild.nodeValue
raise AWSError(code, msg)
return root
if __name__ == '__main__':
api = API(AWS_KEY, SECRET_KEY, 'us',
processor=minidom_response_parser)
root = api.item_lookup('0718155157')
print root.toprettyxml()
# ...
# now do something with it!
示例4: len
# 需要导入模块: from amazonproduct.api import API [as 别名]
# 或者: from amazonproduct.api.API import item_lookup [as 别名]
Get all editorial reviews for books with the specified ISBNs.
"""
import sys
from amazonproduct.api import API
if __name__ == '__main__':
if len(sys.argv[1:]) == 0:
print __doc__
print 'Usage: %s ISBN' % sys.argv[0]
sys.exit(1)
for isbn in sys.argv[1:]:
isbn = isbn.replace('-', '')
# Don't forget to create file ~/.amazon-product-api
# with your credentials (see docs for details)
api = API(locale='us')
for root in api.item_lookup(isbn, IdType='ISBN',
SearchIndex='Books', ResponseGroup='EditorialReview'):
nspace = root.nsmap.get(None, '')
reviews = root.xpath('//aws:EditorialReview',
namespaces={'aws' : nspace})
for review in reviews:
print unicode(review.Source)
print '-' * 40
print unicode(review.Content)
示例5: SoupProcessor
# 需要导入模块: from amazonproduct.api import API [as 别名]
# 或者: from amazonproduct.api.API import item_lookup [as 别名]
# -*- coding: utf-8 -*-
from amazonproduct.api import API
from amazonproduct.errors import AWSError
from amazonproduct.processors import BaseProcessor
import BeautifulSoup
class SoupProcessor(BaseProcessor):
def parse(self, fp):
soup = BeautifulSoup.BeautifulSoup(fp.read())
for error in soup.findAll('error'):
code = error.find('code').text
msg = error.find('message').text
raise AWSError(code, msg)
return soup
if __name__ == '__main__':
api = API(locale='jp', processor=SoupProcessor())
result = api.item_lookup('B00LCL7A3G')
print result
示例6: credentials
# 需要导入模块: from amazonproduct.api import API [as 别名]
# 或者: from amazonproduct.api.API import item_lookup [as 别名]
# Don't forget to create file ~/.amazon-product-api
# with your credentials (see docs for details)
api = API(locale=options.locale)
params = {
'ResponseGroup' : 'Images',
'SearchIndex' : 'All',
'IdType' : options.id_type,
}
# When IdType equals ASIN, SearchIndex cannot be present.
if options.id_type == ASIN:
del params['SearchIndex']
for id in ids:
id = id.replace('-', '')
if options.verbose: print 'Fetching info for %s...' % id
root = api.item_lookup(id, **params)
#~ from lxml import etree
#~ print etree.tostring(root, pretty_print=True)
url = root.Items.Item.LargeImage.URL.pyval
name, ext = os.path.splitext(url)
path = '%s%s' % (id, ext)
if options.verbose: print 'Downloading %s to %s ...' % (url, path)
fetch_image(url, path)