×

Python爬取京东商品历史价格数据

知名用户18007905473 知名用户18007905473 发表于2026-02-13 15:55:36 浏览9 评论0

抢沙发发表评论

核心思路:通过调用京东历史价格接口https://tool.manmanbuy.com/history/getLowPriceList.ashx,获取商品价格走势数据。
技术实现

  1. 接口分析:该接口需传递skucallback参数,返回JSONP格式数据。

  2. 数据清洗:提取pricedate字段,转换为时间序列数据。
    示例代码

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']}")


群贤毕至

访客