博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python批量获取京东商品列表信息
阅读量:4479 次
发布时间:2019-06-08

本文共 1031 字,大约阅读时间需要 3 分钟。

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

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 requestsfrom 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://www.cnblogs.com/xiuluo/p/5740843.html

你可能感兴趣的文章
多态的理解
查看>>
AspNet Core 发布到Linux系统和发布IIS 注意项
查看>>
Windows添加.NET Framework 3.0 NetFx3 失败 - 状态为:0x800f0950
查看>>
隐藏显示终端的光标(shell echo,linux c printf)
查看>>
SQL Server 存储过程
查看>>
JSP 标准标签库(JSTL)(JSP Standard Tag Library)
查看>>
导入项目遇到的问题: Some projects cannot be imported because they already exist in the workspace....
查看>>
华为:字符集合
查看>>
面向对象 【抽象类】【接口】【构造函数】【静态】
查看>>
结构化方法与面向对象方法的比较
查看>>
影响各类服务器性能瓶颈的因素【转】
查看>>
Jenkins
查看>>
jboss5 启动时报HsqlException:length must be specified in type definition:VARBINARY错误
查看>>
转载:让理科生沉默,让文科生流泪的综合题
查看>>
程序员7-2007-2010
查看>>
Android分类前言
查看>>
oracle中字符串的大小比较,字符串与数字的比较和运算
查看>>
2018年东北农业大学春季校赛 wyh的矩阵
查看>>
python网络爬虫与信息提取——4.Beautiful Soup库入门
查看>>
3145 汉诺塔游戏
查看>>