Python “;如何修复&x2018;非类型';对象不可下标”;
我正在尝试从Amazon.com获取产品信息 我在网上搜索了一些代码,找到了一个。我试图修复代码中的错误,但我坚持使用下面的错误。下面代码中的最后一行似乎有问题,因为我遇到了这个错误:Python “;如何修复&x2018;非类型';对象不可下标”;,python,arrays,append,response,amazon,Python,Arrays,Append,Response,Amazon,我正在尝试从Amazon.com获取产品信息 我在网上搜索了一些代码,找到了一个。我试图修复代码中的错误,但我坚持使用下面的错误。下面代码中的最后一行似乎有问题,因为我遇到了这个错误:'NoneType'对象不可订阅 for asin in asin_array: item_array=[] #An array to store details of a single product. amazon_url="https://www.amazon.com/dp/"+asin #
'NoneType'对象不可订阅
for asin in asin_array:
item_array=[] #An array to store details of a single product.
amazon_url="https://www.amazon.com/dp/"+asin #The general structure of a url
response = session.get(amazon_url, headers=headers, verify=False) #get the response
item_array.append(response.html.search('a-color-price">${}<')[0]) #Extracting the price
asin_阵列中asin的:
item_array=[]。#存储单个产品详细信息的数组。
amazon_url=”https://www.amazon.com/dp/“+asin#url的一般结构
response=session.get(amazon_url,headers=headers,verify=False)#获取响应
item_array.append(response.html.search('a-color-price“>${}),因为您的响应是None
基本上,你在试这个吗
print(None[0])
这是不可能的
检查您的响应或搜索标记可能不可用您可以在提取之前检查它:
price_data = response.html.search('a-color-price">${}<')
if price_data:
item_array.append(price_data[0])
price\u data=response.html.search('a-color-price'>${}拷贝将完整的回溯粘贴到您的问题中肯定会有帮助。不过这看起来像是索引问题。response.html.search('a-color-price'>${}