Ich versuche, Bild herunterladen von Webseiten mit Scrapy Framework und Djano-Element. Ich glaube, ich habe wie alles getan, was in doc aber nach scrapy Crawl ruft ich log, die wie folgt aus:Scrapy Bildpipeline lädt keine Bilder
ich nicht, dass es auf alle Informationen finden können, was schief gelaufen ist, aber Bilder Feld leer ist und das Verzeichnis tut keine Bilder enthalten.
Das ist mein Modell
class Event(models.Model):
title = models.CharField(max_length=100, blank=False)
description = models.TextField(blank=True, null=True)
event_location = models.CharField(max_length=100, blank = True, null= True)
image_urls = models.CharField(max_length = 200, blank = True, null = True)
images = models.CharField(max_length=100, blank = True, null = True)
url = models.URLField(max_length=200)
def __unicode(self):
return self.title
und das ist, wie ich aus Spinne Bild-Pipeline gehen
def parse_from_details_page(self, response):
"Some code"
item_event = item_loader.load_item()
#this is to create image_urls list (there is only one image_url allways)
item_event['image_urls'] = [item_event['image_urls'],]
return item_event
und schließlich das ist mein settings.py für Scrapy Projekt:
import sys
import os
import django
DJANGO_PROJECT_PATH = os.path.join(os.path.dirname((os.path.abspath(__file__))), 'MyScrapy')
#sys.path.insert(0, DJANGO_PROJECT_PATH)
#sys.path.append(DJANGO_PROJECT_PATH)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MyScrapy.settings")
#os.environ["DJANGO_SETTINGS_MODULE"] = "MyScrapy.settings"
django.setup()
BOT_NAME = 'EventScraper'
SPIDER_MODULES = ['EventScraper.spiders']
NEWSPIDER_MODULE = 'EventScraper.spiders'
ITEM_PIPELINES = {
'scrapy.pipelines.images.ImagesPipeline': 100,
'EventScraper.pipelines.EventscraperPipeline': 200,
}
#MEDIA STORAGE URL
IMAGES_STORE = os.path.join(DJANGO_PROJECT_PATH, "IMAGES")
#IMAGES (used to be sure that it takes good fields)
FILES_URLS_FIELD = 'image_urls'
FILES_RESULT_FIELD = 'images'
Vielen Dank im Voraus für Ihre Hilfe
EDIT:
ich benutzerdefinierte Bild-Pipeline von doc so aussieht, verwendet
class MyImagesPipeline(ImagesPipeline):
def get_media_requests(self, item, info):
for image_url in item['image_urls']:
import ipdb; ipdb.set_trace()
yield scrapy.Request(image_url)
def item_completed(self, results, item, info):
import ipdb; ipdb.set_trace()
image_paths = [x['path'] for ok, x in results if ok]
if not image_paths:
raise DropItem("Item contains no images")
item['image_paths'] = image_paths
return item
In get_media_requests schafft es Anfrage an meine Url aber in Folge param item_completed i somethin wie diese: [(False, <twisted.python.failure.Failure scrapy.pipelines.files.FileException: >)]
ich noch Ich weiß nicht, wie ich es beheben kann. Kann das Problem möglicherweise durch einen Verweis auf die Adresse mit https verursacht werden?