亚马逊api无法找到降价

时间:2014-11-04 23:13:54

标签: amazon-web-services

我使用下面的代码片段从亚马逊获得红色降价但是simehow我总是得到旧的价格而不是减少的红色价格。

enter code here`def getSignedUrlAmazon(searchvalue):
params = {'ResponseGroup':'Medium',
          'AssociateTag':'',
          'Operation':'ItemSearch',
          'SearchIndex':'All',
          'Keywords':searchvalue}

action = 'GET'`enter code here`
server = "webservices.amazon.in"
path = "/onca/xml"

params['Version'] = '2011-08-01'
params['AWSAccessKeyId'] = AWS_ACCESS_KEY_ID
params['Service'] = 'AWSECommerceService'
params['Timestamp'] = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
# Now sort by keys and make the param string
key_values = [(urllib.quote(k), urllib.quote(v)) for k,v in params.items()]
key_values.sort()

# Combine key value pairs into a string.
paramstring = '&'.join(['%s=%s' % (k, v) for k, v in key_values])
urlstring = "http://" + server + path + "?" + \
    ('&'.join(['%s=%s' % (k, v) for k, v in key_values]))

# Add the method and path (always the same, how RESTy!) and get it ready to sign
hmac.update(action + "\n" + server + "\n" + path + "\n" + paramstring)

# Sign it up and make the url string
urlstring = urlstring + "&Signature="+\
    urllib.quote(base64.encodestring(hmac.digest()).strip())

return urlstring

1 个答案:

答案 0 :(得分:0)

忘了价格抓取部分: def getDataAmazon(searchvalue,PRICE,lock):     尝试:         searchvalue = removeStopWord(searchvalue)         url = getSignedUrlAmazon(searchvalue)         data = etree.parse(url)         root = objectify.fromstring(etree.tostring(data,pretty_print = True))

    gd=[]
    gd1=[]
    counter = 0
    if hasattr(root, 'Items') and hasattr(root.Items, 'Item'):
        for item in root.Items.Item:
            cd={}
            priceCheckFlag = False
            try :

                if hasattr(item.ItemAttributes, 'EAN'):
                    cd['EAN']       = str(item.ItemAttributes.EAN)
                elif hasattr(item, 'ASIN'):
                    cd['ASIN']      = str(item.ASIN)
                cd['productName']   = str(item.ItemAttributes.Title)
                if hasattr(item, 'SmallImage'):
                    cd['imgLink']   = str(item.SmallImage.URL)
                elif hasattr(item, 'MediumImage'):
                    cd['imgLink']   = str(item.MediumImage.URL)
                cd['numstar']       = "0"

                cd['productdiv']    = '1'
                cd['sellername']    = 'Amazon'
                if hasattr(item, 'DetailPageURL'):
                    cd['visitstore']     = str(item.DetailPageURL)
                if hasattr(item.ItemAttributes, 'ListPrice') and hasattr(item.ItemAttributes.ListPrice, 'Amount'):
                    cd['price']     = item.ItemAttributes.ListPrice.Amount/100.0
                elif hasattr(item, 'OfferSummary') and hasattr(item.OfferSummary, 'LowestNewPrice'):
                    cd['price']     = item.OfferSummary.LowestNewPrice.Amount/100.0