Python 爬虫 | 获取集合竞价数据
import requests
import json
# 替换为你的API密钥
api_key = 'YOUR_API_KEY'
# 获取商品信息
def get_product_info(asin):
params = {
'key': api_key,
'asin': asin,
'responseGroup': 'Medium,Images,Offers,Reviews'
}
url = 'https://api.bazaarvoice.com/data/reviews/product/v2'
response = requests.get(url, params=params)
if response.status_code == 200:
return response.json()
else:
print('Error retrieving product info for ASIN:', asin)
return None
# 获取竞价信息
def get_competitive_pricing_data(asin):
params = {
'key': api_key,
'asin': asin,
'responseGroup': 'Competitive'
}
url = 'https://api.bazaarvoice.com/data/reviews/product/v2'
response = requests.get(url, params=params)
if response.status_code == 200:
return response.json()
else:
print('Error retrieving competitive pricing data for ASIN:', asin)
return None
# 示例ASIN
asin = 'B01M8BPKSZ'
# 获取并打印商品信息
product_info = get_product_info(asin)
print(json.dumps(product_info, indent=2))
# 获取并打印竞价信息
competitive_pricing_data = get_competitive_pricing_data(asin)
print(json.dumps(competitive_pricing_data, indent=2))
这段代码首先定义了API密钥和需要的函数。get_product_info
函数用于获取特定ASIN的商品信息,而get_competitive_pricing_data
函数用于获取该商品的竞价信息。然后,代码使用示例ASIN调用这些函数,并打印返回的JSON数据。注意,你需要替换YOUR_API_KEY
为你的实际API密钥,并确保API服务是可用的。
评论已关闭