Как скачать с помощью python scrapy - PullRequest
0 голосов
/ 14 апреля 2020

Я получаю список URL, но изображения не загружаются.

import scrapy
from ..items import GoogleItem

class spider(scrapy.Spider):

    name = 'google'
    start_urls = [
        "https://www.google.com/search?q=selena%20gomez&spell=1&ie=UTF-8&gbv=1&tbm=isch&sxsrf=ALeKk01ILeLRLtOpXXVyxa1PQYz38RnbRg%3A1586860191506&ei=n5CVXu2GHPGY4-EPreeA-AM&sa=N&btnG=Search"
    ]

    def parse(self, response):
        item = GoogleItem()
        img_url =[]
        for image in response.xpath('/html/body/table[4]/tr/td/a/img/@src').extract():
            img_url.append(image)

        item["image_urls"]= img_url

        return item

В элементе я сделал это:

import scrapy


class GoogleItem(scrapy.Item):
    images = scrapy.Field()
    image_urls = scrapy.Field()

в настройках, это:

ITEM_PIPELINES = {
    'test_scrapy.pipelines.TestScrapyPipeline': 1,
}


IMAGE_STORE ="E:/New folder/image"

Я получаю это в своем терминале по ссылкам с URL-адресами изображений:

{'downloader / request_bytes': 404, 'downloader / request_count': 1,

что я сделал не так ??

1 Ответ

0 голосов
/ 15 апреля 2020

Ваш ITEM_PIPELINE также должен включать конвейер загрузки изображений:

ITEM_PIPELINES = {
    # your pipeline that adds `image_urls` field
    'test_scrapy.pipelines.TestScrapyPipeline': 1,
    # scrapy's pipeline taht downloads images
    'scrapy.pipelines.images.ImagesPipeline': 999,
}

Для получения дополнительной информации см. Официальные документы в медиа-конвейерах: https://docs.scrapy.org/en/latest/topics/media-pipeline.html#enabling -your-media-pipe

...