Scrapy定制管道爬取pexels.com网站信息

本文介绍了使用Scrapy框架定制管道爬取pexels.com网站信息的过程,包括处理文本和图片。在实践中遇到的问题是,虽然预期应爬取60张图片,但实际只下载了40张。分析发现,第41个图片URL为空,导致图片处理管道提前终止。解决方案是在构建列表时增加非空判断,避免None值导致的问题。同时,文章提到了网页预加载导致部分图片无法直接获取的问题,并给出了相应的解决策略。
摘要由CSDN通过智能技术生成

参考了官方文档,链接https://scrapy-chs.readthedocs.io/zh_CN/latest/topics/images.html

处理文本的pipeline参考了这篇博客https://blog.csdn.net/killeri/article/details/80228089

items.py:

import scrapy

class XicidailispiderItem(scrapy.Item):
    # define the fields for your item here like:
    # name = scrapy.Field()
    image_urls = scrapy.Field()
    images = scrapy.Field()
    image_paths=scrapy.Field()
    photographer=scrapy.Field()

爬虫文件:

class PexelcrawlSpider(scrapy.Spider):
    name = 'pexelCrawl'
    allowed_domains = ['pexels.com']
    start_urls = ['https://www.pexels.com/']

    def parse(self, response):
        selectors = res
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值