无法使用scrapy下载图像

SIM*_*SIM 7 python scrapy web-scraping python-3.x scrapy-spider

我已经用python scrapy编写了一个脚本来从网站下载一些图像.当我运行我的脚本时,我可以.jpg在控制台中看到图像的链接(所有这些都是格式化的).但是,当我打开下载完成后应该保存图像的文件夹时,我什么都没有.我在哪里犯错误?

这是我的蜘蛛(我从崇高的文本编辑器运行):

import scrapy
from scrapy.crawler import CrawlerProcess

class YifyTorrentSpider(scrapy.Spider):
    name = "yifytorrent"

    start_urls= ['https://www.yify-torrent.org/search/1080p/']

    def parse(self, response):
        for q in response.css("article.img-item .poster-thumb"):
            image = response.urljoin(q.css("::attr(src)").extract_first())
            yield {'':image}

c = CrawlerProcess({
    'USER_AGENT': 'Mozilla/5.0',   
})
c.crawl(YifyTorrentSpider)
c.start()
Run Code Online (Sandbox Code Playgroud)

这是我settings.py为要保存的图像定义的内容:

ITEM_PIPELINES = {
    'scrapy.pipelines.images.ImagesPipeline': 1,
}
IMAGES_STORE = "/Desktop/torrentspider/torrentspider/spiders/Images"
Run Code Online (Sandbox Code Playgroud)

为了使事情更清楚:

  1. 我希望保存图像Imagesspider文件夹命名为我放在项目下的文件夹中torrentspider.
  2. Images文件夹的实际地址是C:\Users\WCS\Desktop\torrentspider\torrentspider\spiders.

这不是关于在items.py文件的帮助下成功运行脚本.因此,任何使用items.py文件进行下载的解决方案都不是我想要的.

gus*_*idd 3

您生成的项目不遵循 Scrapy 的文档。正如他们的媒体管道文档中详细描述的,该项目应该有一个名为 的字段image_urls。您应该将解析方法更改为与此类似的方法。

def parse(self, response):
    images = []
    for q in response.css("article.img-item .poster-thumb"):
        image = response.urljoin(q.css("::attr(src)").extract_first())
        images.append(image)
    yield {'image_urls': images} 
Run Code Online (Sandbox Code Playgroud)

我刚刚测试了这个并且它有效。此外,正如 Pruthvi Kumar 所评论的那样,IMAGES_STORE 应该就像

IMAGES_STORE = 'Images'
Run Code Online (Sandbox Code Playgroud)