2014-11-04 91 views
0

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

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 

回答

0

忘记价格抓取部分: DEF getDataAmazon(searchvalue,价格,锁): 尝试: searchvalue = removeStopWord(searchvalue) URL = getSignedUrlAmazon(searchvalue) 数据=调用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