Python批量获取京东商品列表信息

本文介绍了一种利用Python从京东批量获取商品价格的方法。通过解析网页获取商品ID,并调用京东API接口来抓取商品的价格信息。文章还提供了一份简易的Python脚本示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天在逛网站的时候无意间发现一个京东获取单个商品价格接口:

http://p.3.cn/prices/mgets?skuIds=J_商品ID&type=1 用例

ps:商品ID这么获取:http://item.jd.com/954086.html

于是我就从Google上找了利用此接口批量获取价格信息的源码,稍作修改使其支持Python3(PS:通过这段代码,我对Python的易用性不再怀疑了,23333)

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
 
url = 'http://list.jd.com/list.html?cat=9987,653,655&page=1&delivery=1&trans=1&JL=4_21_0' request = requests.get(url) soup = BeautifulSoup(request.text, "html.parser") items = soup.select('li.gl-item') i = 1 for item in items: sku = item.find('div')['data-sku'] price_url = 'http://p.3.cn/prices/mgets?skuIds=J_' + str(sku) price = requests.get(price_url).json()[0]['p'] name = item.find('div', class_="p-name").find('em').string item_url = 'http:' + item.find('div', class_="p-name").find('a')['href'] commit = item.find('div', class_="p-commit").find('a').string print("%d、\n 名称: %s \n 价格: %s 元 \n 评价: %s 个 \n 链接: %s" % (i, name, price, commit, item_url)) if i >= 10: break else: i += 1

效果:

安利一下个人博客:https://cxfer.cn/2016/75.html

转载于:https://www.cnblogs.com/xiuluo/p/5740843.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值