核心思路:通过调用京东历史价格接口https://tool.manmanbuy.com/history/getLowPriceList.ashx,获取商品价格走势数据。
技术实现:
接口分析:该接口需传递
sku和callback参数,返回JSONP格式数据。数据清洗:提取
price和date字段,转换为时间序列数据。
示例代码:
import requests, re, json
def get_price_history(sku_id):
url = f"https://tool.manmanbuy.com/history/getLowPriceList.ashx?sku={sku_id}"
response = requests.get(url)
# 提取JSONP数据中的JSON部分
json_str = re.search(r"jQuery\d+\((.*?)\);", response.text).group(1)
data = json.loads(json_str)
return data["priceList"]
# 使用示例
history = get_price_history("100000000001")
for entry in history:
print(f"Date: {entry['date']}, Price: {entry['price']}")