Python爬虫(5)——获取京东手机图片
2017-06-08 17:55
666 查看
代码如下所示:
爬取结果如下图所示:
# -*- coding: utf-8 -*- """ Created on Thu Jun 8 15:24:27 2017 @author: zch """ import re import urllib.request def craw(url,page): #获取网页源代码 html1 = urllib.request.urlopen(url).read() html1 = str(html1) #对网页源码进行过滤,只保留和产品列表相关的信息 pat1 = '<div id="plist".+? <div class="page clearfix">' result1 = re.compile(pat1).findall(html1) result1 = result1[0] #print(result1) #再次过滤,提取网页中图片的链接,并将链接地址存储在列表中 pat2 = '<img width="220" height="220" data-img="1" data-lazy-img="//(.+?\.jpg)">' imagelist = re.compile(pat2).findall(result1) x = 1 #遍历列表,将链接存储到本地 for imageurl in imagelist: imagename = "E:/Python/data/jd/img1/" + str(page) + str(x) + ".jpg" imageurl = "http://" + imageurl try: urllib.request.urlretrieve(imageurl,filename=imagename) except urllib.error.URLError as e: if hasattr(e,"code"): x+=1 if hasattr(e,"reason"): x+=1 x+=1 #通过for循环,将该分类下的所有网页都爬取一遍 for i in range(1,88): url = "https://list.jd.com/list.html?cat=9987,653,655&page="+str(i) craw(url,i)
爬取结果如下图所示:
相关文章推荐
- python爬虫获取京东手机图片的图文教程
- python爬虫获取京东手机图片
- 爬虫案例---Python2X版本抓取京东手机页面的图片
- 07精通Python网络爬虫——爬取京东手机图片
- Python爬虫实现爬取京东手机页面的图片(实例代码)
- python3.X爬虫-图片获取
- python简单爬虫(获取图片)
- python 爬虫获取网页图片
- python3[爬虫实战] 使用selenium,xpath爬取京东手机(下)
- python爬虫 分页获取图片并下载
- python爬虫三:获取一个网易用户的所有图片(selenium+phantomjs)
- Python实现简单的获取图片爬虫功能示例
- python爬虫 分页获取图片并下载
- python3[爬虫实战] 使用selenium,xpath爬取京东手机(上)
- python3[爬虫实战] 使用selenium,xpath爬取京东手机(下)
- python利用urllib实现爬取京东网站商品图片的爬虫实例
- Python3爬虫入门之贴吧图片批量获取
- Python爬虫_简单获取百度贴吧图片
- Python 爬虫:获取网页图片
- Python爬虫获取图片并下载保存至本地