Я использую scrapy для загрузки изображений, но это не работает.Я получаю URL в нужной папке, но не изображения.
Вот мои items.py:
class Brand(scrapy.Item):
name = scrapy.Field()
url = scrapy.Field()
brand_image = scrapy.Field()
image_urls = scrapy.Field()
images = scrapy.Field()
pass
Вот мой код паука:
import scrapy
import json
from scraper.items import Brand
class QuotesSpider(scrapy.Spider):
name = "brandDetails"
def start_requests(self):
with open('brands.json') as data_file:
data_item = json.load(data_file)
urls = list()
for item in data_item:
urls.append(item["url"])
for url in urls:
yield scrapy.Request(url=url, callback=self.parse)
def parse(self, response):
item = Brand()
name = response.css("div.th::text").extract_first()
name = name.replace('Products of ', '')
item['name'] = name
item['url'] = response.url
urls = response.css("div.productimage img::attr(src)").extract_first()
urls = "http://ozhat-turkiye.com" + urls
item['image_urls'] = urls
yield item
Здесьэто код установки:
BOT_NAME = 'scraper'
SPIDER_MODULES = ['scraper.spiders']
NEWSPIDER_MODULE = 'scraper.spiders'
IMAGE_STORE = 'C:/Users/SHAHRUKH/Desktop/AI'
ITEM_PIPELINES = {
'scrapy.pipelines.images.ImagesPipeline': 1
}
DOWNLOAD_DELAY = 2
Вот вывод моей программы:
{'image_urls': 'http://ozhat-turkiye.com/get.aspx?id=1882267',
'name': ' Camille Bauer',
'url': 'http://ozhat-turkiye.com/en/camille-bauer/'}