参考 : https://www.jianshu.com/p/6c8d2730d088

https://docs.scrapy.org/en/latest/topics/item-pipeline.html#writing-your-own-item-pipeline

import scrapy

import requests

import os

class MeinvSpider(scrapy.Spider):
     name = "get_meinv"

start_urls = [
         'https://www.du114.com/',
     ]

def parse(self, response):

dir_path = '%s/%s' % (".", self.name)

if not os.path.exists(dir_path):
             os.makedirs(dir_path)

for imggroup in response.css('div.Column-picBox'):
             imgset = imggroup.css('ul>li img::attr("src")')
             for image_url in imgset.extract():

print("image_url=%s" % image_url)

us = image_url.split('/')[3:]
                 image_file_name = '_'.join(us)
                 file_path = '%s/%s' % (dir_path, image_file_name)

if os.path.exists(file_path):
                     continue

with open(file_path, 'wb') as handle:
                     response = requests.get(image_url, stream=True)
                     for block in response.iter_content(1024):
                         if not block:
                             break

handle.write(block)

Scrapy 下载图片的更多相关文章

  1. scrapy下载图片到自己的目录,创建缩略图,存储入库

    环境和工具:python2.7,scrapy 实验网站:http://www.27270.com/tag/333.html  爬去所有兔女郎图片,下面的推荐需要过滤 逻辑:分析网站信息,下载图片和入库 ...

  2. Scrapy下载图片及自定义分类下载路径

    配置下载图片的流程如下 在items中定义两个属性,image_urls 和images .image_urls是用来存储需要下载的图片url链接,列表类型: 当文件下载完成后会把相关下载信息存入im ...

  3. 利用scrapy下载图片保存到本地

    1.先声明一下,起始位置已经是将所有的图片链接都能到pipelines.py中 2.创建一个类,继承于ImagesPipeline,因此也就需要导入ImagesPipeline from scrapy ...

  4. scrapy 下载图片 from cuiqingcai

    import scrapy class MzituScrapyItem(scrapy.Item): # define the fields for your item here like: # nam ...

  5. [转]解决scrapy下载图片时相对路径转绝对路径的问题

    专注自:http://blog.csdn.net/hjy_six/article/details/6862648 这段时间一直在研究利用scrapy抓取图片的问题,我发觉,用官网的http://doc ...

  6. Scrapy 下载图片时 ModuleNotFoundError: No module named'PIL'

    使用scrapy的下载模块需要PIL(python图像处理模块)的支持,使用pip安装即可

  7. scrapy下载图片报[scrapy.downloadermiddlewares.robotstxt] DEBUG: Forbidden by robots.txt:错误

    本文转自:http://blog.csdn.net/zzk1995/article/details/51628205 先说结论,关闭scrapy自带的ROBOTSTXT_OBEY功能,在setting ...

  8. Day3-scrapy爬虫下载图片自定义名称

    学习Scrapy过程中发现用Scrapy下载图片时,总是以他们的URL的SHA1 hash值为文件名,如: 图片URL:http://www.example.com/image.jpg 它的SHA1 ...

  9. 用Scrapy爬虫下载图片(豆瓣电影图片)

    用Scrapy爬虫的安装和入门教程,这里有,这篇链接的博客也是我这篇博客的基础. 其实我完全可以直接在上面那篇博客中的代码中直接加入我要下载图片的部分代码的,但是由于上述博客中的代码已运行,已爬到快九 ...

随机推荐

  1. leetcode 5 查找最长的回文子串

    给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 的最大长度为 1000. 示例 1: 输入: "babad" 输出: "bab" 注意: &qu ...

  2. WiFi其他方法和WiFi事件响

    https://blog.csdn.net/Naisu_kun/article/details/86079455 目的WiFi在使用过程中并非会一直如希望般稳定运行的,为了应对这些情况就需要能够了解W ...

  3. 关于mysql中unique的插入Duplicate key

    MySQL数据库中 如果在后台中不做判断是否unique的column是否存在的话,直接把数据操作给dao层再传给DB的话,就会报重复的唯一值.如果确实是不希望先取出判断unique的column是否 ...

  4. 三种dedecms友情链接调用标签

    三种dedecms友情链接调用标签: 1.获取友情链接分类 {dede:flinktype}<span>[field:typename/]</span>{/dede:flink ...

  5. java list map set array 转换

    1.list转set Set set = new HashSet(new ArrayList()); 2.set转list List list = new ArrayList(new HashSet( ...

  6. JS实现刷新页面后回到记录时滚动条的位置

    window.onbeforeunload = function () { var scrollPos; if (typeof window.pageYOffset != 'undefined') { ...

  7. ABP mysql

    SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator ...

  8. Java基础-1

    基础知识 1.进制 1.十进制 2.二进制 3.十六进制 2.十六进制转换 二进制转换 十进制转换

  9. Python--Linux上安装Python

    Linux 上安装 Python 官网下载:https://www.python.org/downloads/ 本文安装包下载链接:https://pan.baidu.com/s/1uL2JyoY_g ...

  10. CentOS6.5安装ElasticSearch6.2.3

    CentOS6.5安装ElasticSearch6.2.3 1.Elastic 需要 Java 8 环境.(安装步骤:http://www.cnblogs.com/hunttown/p/5450463 ...