本例程使用urlib实现的,基于python2.7版本,采用beautifulsoup进行网页分析,没有第三方库的应该安装上之后才能运行,我用的IDE是pycharm,闲话少说,直接上代码!

 # -*- coding: utf-8 -*
import re
import os
import urllib
import urllib2
from bs4 import BeautifulSoup
def craw(url,page):
html1=urllib2.urlopen(url).read()
html1=str(html1)
soup=BeautifulSoup(html1,'lxml')
imagelist=soup.select('#J_goodsList > ul > li > div > div.p-img > a > img')
namelist=soup.select('#J_goodsList > ul > li > div > div.p-name > a > em')
#pricelist=soup.select('#plist > ul > li > div > div.p-price > strong')
#print pricelist
path = "E:/{}/".format(str(goods))
if not os.path.exists(path):
os.mkdir(path)
for (imageurl,name) in zip(imagelist,namelist):
name=name.get_text()
imagename=path + name +".jpg"
imgurl="http:"+str(imageurl.get('data-lazy-img'))
if imgurl == 'http:None':
imgurl = "http:" + str(imageurl.get('src'))
try:
urllib.urlretrieve(imgurl,filename=imagename)
except:
continue '''
#J_goodsList > ul > li:nth-child(1) > div > div.p-img > a > img
#plist > ul > li:nth-child(1) > div > div.p-name.p-name-type3 > a > em
#plist > ul > li:nth-child(1) > div > div.p-price > strong:nth-child(1) > i
''' if __name__ == "__main__":
goods=raw_input('please input the goos you want:')
pages=input('please input the pages you want:')
count =0.0
for i in range(1,int(pages+1),2):
url="https://search.jd.com/Search?keyword={}&enc=utf-8&qrst=1&rt=1&stop=1&vt=2&suggest=1.def.0.T06&wq=diann&page={}".format(str(goods),str(i))
craw(url,i)
count += 1
print 'work completed {:.2f}%'.format(count/int(pages)*100)

图片的命名为商品的名称,京东商品图片地址的属性很可能会有所变动,所以大家进行编写的时候应该举一反三,灵活运用! 
这是我下载下来的手机类图片文件的截图: 

我本地的爬取的速度很快,不到一分钟就能爬取100页上千个商品的图片!

python利用urllib实现的爬取京东网站商品图片的爬虫的更多相关文章

  1. python爬取某个网站的图片并保存到本地

    python爬取某个网站的图片并保存到本地 #coding:utf- import urllib import re import sys reload(sys) sys.setdefaultenco ...

  2. Scrapy实战篇(八)之Scrapy对接selenium爬取京东商城商品数据

    本篇目标:我们以爬取京东商城商品数据为例,展示Scrapy框架对接selenium爬取京东商城商品数据. 背景: 京东商城页面为js动态加载页面,直接使用request请求,无法得到我们想要的商品数据 ...

  3. JS+Selenium+excel追加写入,使用python成功爬取京东任何商品~

    之前一直是requests库做爬虫,这次尝试下使用selenium做爬虫,效率不高,但是却没有限制,文章是分别结合大牛的selenium爬虫以及excel追加写入操作而成,还有待优化,打算爬取更多信息 ...

  4. 毕设二:python 爬取京东的商品评论

    # -*- coding: utf-8 -*- # @author: Tele # @Time : 2019/04/14 下午 3:48 # 多线程版 import time import reque ...

  5. scrapy+splash 爬取京东动态商品

    作业来源:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/3159 splash是容器安装的,从docker官网上下载windows下的 ...

  6. Python爬取mn52网站美女图片以及图片防盗链的解决方法

    防盗链原理 http标准协议中有专门的字段记录referer 一来可以追溯上一个入站地址是什么 二来对于资源文件,可以跟踪到包含显示他的网页地址是什么 因此所有防盗链方法都是基于这个Referer字段 ...

  7. 利用requests, beautifulsoup包爬取股票信息网站

    这是第一次用requests, beautifulsoup实现爬虫,此次爬取的是一个股票信息网站:http://www.gupiaozhishi.net.cn. 实现非常简单,只是为了demo使用的数 ...

  8. Python每日一练(3):爬取百度贴吧图片

    import requests,re #先把要访问URL和头部准备好 url = 'http://tieba.baidu.com/p/2166231880' head = { 'Accept': '* ...

  9. 一起学爬虫——使用selenium和pyquery爬取京东商品列表

    layout: article title: 一起学爬虫--使用selenium和pyquery爬取京东商品列表 mathjax: true --- 今天一起学起使用selenium和pyquery爬 ...

随机推荐

  1. PHP通过phpmailer批量发送邮件功能

    前端页面代码: 注意:目前发送人使用的qq邮箱支持的不是特别友好.建议使用网易 新浪 163等其他邮箱. 需要用到phpmailer包 下载地址:https://sourceforge.net/pro ...

  2. div+css命名规范大全

    网页制作中规范使用DIV+CSS命名规则,可以改善优化功效特别是团队合作时候可以提供合作制作效率, 我们开发DIV+CSS网页(Xhtml)时候,比较困惑和纠结的事就是CSS命名,特别是新手不知道什么 ...

  3. WebService中的WSDL详解 及jmeter测试

    首先简单讲解一下什么是wsdl.        一个WSDL文档通常包含8个重要的元素,即definitions.types.import.message.portType.operation.bin ...

  4. gdb命令中查看地址之x命令

    可以使用examine命令(简写是x)来查看内存地址中的值.x命令的语法如下所示: x/<n/f/u> <addr> n.f.u是可选的参数. n是一个正整数,表示需要显示的内 ...

  5. 13. leetcode 453. Minimum Moves to Equal Array Elements

    Given a non-empty integer array of size n, find the minimum number of moves required to make all arr ...

  6. NYOJ--20--搜索(dfs)--吝啬的国度

    题意,N座城市有N-1条路,目的是找到哪个城市可以到目的城市 //NYOJ--search--吝啬的国度 #include<iostream> #include<vector> ...

  7. 安徽省2016“京胜杯”程序设计大赛_F_吃在工大

    吃在工大 Time Limit: 1000 MS Memory Limit: 65536 KB Total Submissions: 51 Accepted: 15 Description      ...

  8. 開源sources

    學了c++已經快有半年光景,感覺在停留在syntax上已經不能感到有所滿足.一下是一些開源資料,難度極高,姑且當作是個人的一個小小wishing list,當作to-do list 般去執行吧. ht ...

  9. RocketMQ入门

    本文首先引出消息中间件通常需要解决哪些问题,在解决这些问题当中会遇到什么困难,Apache RocketMQ作为阿里开源的一款高性能.高吞吐量的分布式消息中间件否可以解决,规范中如何定义这些问题.然后 ...

  10. Oracle Test 日志

    这是一个在本地写日志的软件,写一篇看看效果怎么样. 我主要想看看这个行间距ok不... 看看效果...