猿问

在尝试加载图像时,scrapy 返回“响应内容不是文本”

我正在尝试使用scrapy下载图像,但返回以下错误:


raise NotSupported("Response content isn't text")

scrapy.exceptions.NotSupported: Response content isn't text

2018-11-30 14:36:09 [scrapy.core.scraper] ERROR: Spider error processing <GET https://www.example.bla/39307b2103.jpg> 

这是我正在使用的相应代码:


...

myitem['i10_img']       = 'https://www.example.de' + response.css("#fullscreen_img::attr(src)").extract_first()[2:]

yield scrapy.Request(myitem['i10_img'],callback=self.parseImages,  meta={'item': myitem})


return myitem


def parseImages(self, response):

    for elem in response.xpath("//img"):

        img_url = elem.xpath("@src").extract_first()

        yield ImageItem(image_urls=[img_url])

项目.py


class ImageItem(scrapy.Item):

image_urls = scrapy.Field()

images = scrapy.Field()

我需要在 yield 命令中进行一些调整吗?


喵喔喔
浏览 1140回答 1
1回答

aluckdog

我认为您误解了图像管道的工作原理。您正在尝试创建对图像 url 本身的请求并将其解析为 HTML。相反,您应该简单地将图像 url 添加到image_urlsof&nbsp;myitem(就像您尝试在 中所做的那样parseImages)。
随时随地看视频慕课网APP

相关分类

Python
我要回答