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

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

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

时间: 2024-08-29 17:54:42

Python批量获取京东商品列表信息的相关文章

京东价格监控软件开发技术探讨七:如何获取京东商品评价信息

在购买商品的时候,这个商品质量怎么样.价格贵不贵.商家服务态度好不好?这些问题往往是购买者急需知道的信息. 京东平台提供了商品评价功能,能够让购买者通过其他购买者的反馈来决定自己到底买不买这个商品. 项目组在对"杀京东"程序进行需求调研时,认为提供商品的评价尤其是差评信息,对购买者非常有指导意义,能加强用户的操作体验.此时,如何获取京东商品的评价信息成为项目组的首要任务. 首先还是先上神器Fiddler,通过它来获取到访问地址. //差评 http://club.jd.com/prod

Python爬取京东商品数据

对京东某一商品信息页面的HTML代码进行分析,可以发现它的图书产品信息页面都含有这样一段代码(不同类的商品页面有些不同): window.pageConfig={compatible:true,searchType: 1,product:{"skuid":"11408255","name":"\u4f17\u795e\u7684\u536b\u661f\uff1a\u4e2d\u56fd\u7981\u533a","

Python爬虫实战(2):爬取京东商品列表

1,引言 在上一篇<Python爬虫实战:爬取Drupal论坛帖子列表>,爬取了一个用Drupal做的论坛,是静态页面,抓取比较容易,即使直接解析html源文件都可以抓取到需要的内容.相反,JavaScript实现的动态网页内容,无法从html源代码抓取需要的内容,必须先执行JavaScript. 我们在<Python爬虫使用Selenium+PhantomJS抓取Ajax和动态HTML内容>一文已经成功检验了动态网页内容的抓取方法,本文将实验程序进行改写,使用开源Python爬虫

四、京东商品列表查询

product_list.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix=&quo

Python实现获取Linux操作系统基础信息

获取信息如下: 主机名 系统版本 系统内核版本 总内存 CPU生厂商 CPU总核心数 服务器生厂商 服务器序列号 各网卡IP,MAC和网卡名信息 实现代码如下: #!/usr/bin/python #coding:utf8 from subprocess import Popen, PIPE import re #获取主机名,也可以使用 uname -n 命令获取 def hostname():     hostname = Popen(["hostname"], stdout=PIP

使用Python自动获取可用代理列表

今天闲来无事,随便写的一个从代理发布网站上提取可用代理列表的脚本.运行后,可以获取 http://cn-proxy.com/ 发布的可用代理ip和端口的列表. 运行效果如下: 源代码如下,请指教: # -*- coding: utf-8 -*- # Python:      2.7.8 # Platform:    Windows # Author:      wucl # Program:     从代理网站获取可用代理 # History:     2015.6.11 import urll

Python批量抓取商品数据

(批量抓取pids.csv文件中商品数据)pids.csv 文件内容:pid733641371225907336415 报错: 解决后代码: 原文地址:http://blog.51cto.com/2290153/2125131

Python 批量获取Google用户动态 (分页)

CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-9-7 @author: guaguastd @name: user_activity_loop.py ''' import json from login import google_api_request from html import cleanHtml import os MAX_RESULTS = 40 while True: query = raw

Python 之 获取Host Esxi 主机信息

代码 #Author Kang #获取ESXI主机的CPU和内存使用情况,并统计百分比 import ssl import pysphere from pysphere import VIServer,MORTypes,VIProperty from pysphere.resources import VimService_services as VI ssl._create_default_https_context = ssl._create_unverified_context host_