IndexError:列表索引超出范围,Python,Amazon.com审查检索

时间:2015-02-04 14:06:41

标签: python xml amazon review

from xml.dom import minidom
import bottlenose
import time
ACCESS_KEY_ID = '''Your access key id in quotes'''
SECRET_KEY = '''your secret key in quotes'''
ASSOC_TAG =''' your associate tag in quotes'''

myList=[]
myList1=[]


response=None
pname=raw_input("Enter your product name")  '''Enter Product name to retrieve reviews'''
mname=''.join(e for e in pname if e.isalnum()) 
mname=mname.lower() 
'''remove special characters and spaces from product name and convert all letters to lowercase'''
amazon = bottlenose.Amazon(ACCESS_KEY_ID, SECRET_KEY, ASSOC_TAG)

while True:
        try:
            response=amazon.ItemSearch(Keywords=pname,    SearchIndex="Electronics",Region="IN",Timeout='60') 
                '''search item by keyword, set Region as India(IN)'''
        print "connect"                                              
            break
        except:
            print "Setting up connection. Make sure you are connected to internet"
        time.sleep(5)

resp_object = minidom.parseString(response)     '''get response object from xml response'''
urls = resp_object.getElementsByTagName('DetailPageURL')  '''retrieve all page urls matching keyword'''
ids = resp_object.getElementsByTagName('ASIN') 
'''retrieve unique product ids corresponding to urls'''
for i in urls:
    url=i.firstChild.nodeValue
    url=''.join(e for e in url if e.isalnum())   '''removing special characters from url'''
    url=url.lower()              '''getting each url one by one from url set'''

    if mname in url:

        myList.append(i.firstChild.nodeValue) 
              '''append to myList if entered product name appears in url'''
        myList1.append(url)

for identify in ids:

    temp=identify.firstChild.nodeValue.lower()
     '''getting each id from id list'''
    if temp in myList1[0]:                            
        itemid=temp    '''if any id appears in url, append id to varaiable 'itemid' '''  



response = amazon.ItemLookup(ItemId=itemid.upper(), ResponseGroup="Reviews",Timeout='60')

resp_object = minidom.parseString(response)
urls = resp_object.getElementsByTagName('IFrameURL') 
  '''retrieving iframe url of reviews of products matching the id in itemid'''
for i in urls: 
    print i.firstChild.nodeValue
上面执行

给我一​​个像这样的错误

如果myList1 [0]中的temp:
IndexError:列表索引超出范围

我试图从亚马逊检索评论而我在处理响应对象时遇到问题。我该怎么做才能解决错误?

0 个答案:

没有答案