scrapy——图片数据爬取之 ImagesPipeline

  • 图片数据爬取之ImagesPipeline
    • 基于scrapy爬取字符串类型的数据和爬取图片类型的数据的区别?
      • 字符串:只需要基于xpath进行解析且提交管道进行持久化存储。
      • 图片:xpath解析出图片src的属性值。单独的对图片地址发起请求获取图片二进制类型的数据
    • xpath 提供了 imagespipeline 帮助我们处理图片的src,只需要将img的src的属性值进行解析,提交到管道,管道就会对图片的src属性值进行请求发送获取图片的二进制类型的数据,且还会帮助我们进行持久化存储
    • 需求:爬取站长素材中的高清图片
    • 使用流程:
      • 数据解析(图片的地址)
      • 将存储图片的item提交给指定的管道类
      • 在管道文件中自定制一个基于ImagesPipeLine的一个管道类,需要重写三个方法:
        • get_media_request()
        • file_path()
        • item_completed()
      • 在配置文件中(settings):
        • 指定图片存储的目录:IMAGES_STORE = ‘./imgs’
        • 指定开启的管道:(基于自定制的管道类)

setting.py

# -*- coding: utf-8 -*-

# Scrapy settings for imgsPro project
#
# For simplicity, this file contains only settings considered important or
# commonly used. You can find more settings consulting the documentation:
#
#     https://doc.scrapy.org/en/latest/topics/settings.html
#     https://doc.scrapy.org/en/latest/topics/downloader-middleware.html
#     https://doc.scrapy.org/en/latest/topics/spider-middleware.html

BOT_NAME = 'imgsPro'

SPIDER_MODULES = ['imgsPro.spiders']
NEWSPIDER_MODULE = 'imgsPro.spiders'

LOG_LEVEL = 'ERROR'
# Crawl responsibly by identifying yourself (and your website) on the user-agent
USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'

# Obey robots.txt rules
ROBOTSTXT_OBEY = False

# Configure maximum concurrent requests performed by Scrapy (default: 16)
#CONCURRENT_REQUESTS = 32

# Configure a delay for requests for the same website (default: 0)
# See https://doc.scrapy.org/en/latest/topics/settings.html#download-delay
#
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值