在Scrapy演示中,ImagePipeline无法添加到settings.py

时间:2018-03-29 15:46:50

标签: python scrapy web-crawler

在我的Scrapy演示中,类扩展ImagesPipelines无法添加到settings.py中。 这是我的pipelines.py:

class Douyu3Pipeline(ImagesPipeline):

    IMAGES_STORE = get_project_settings().get("IMAGE_STORE")

    def get_media_requests(self, item, info):
        print("1---------------------------1")
        image_url = item["imagelink"]
        yield scrapy.Request(image_url)

    def item_completed(self, results, item, info):
        image_path = [x["path"] for ok, x in results if ok]
        os.rename(self.IMAGES_STORE + "/" + image_path[0],
                  self.IMAGES_STORE + "/" + item["nickname"] + ".jpg")
        item['imagePath'] = self.IMAGES_STORE + '/' + item['nickname']
        return item

这是我的settings.py:

BOT_NAME = 'douyu3'
SPIDER_MODULES = ['douyu3.spiders']
NEWSPIDER_MODULE = 'douyu3.spiders'
ROBOTSTXT_OBEY = True
DEFAULT_REQUEST_HEADERS = {
    'User-Agent': 'DYZB/1 CFNetwork/808.2.16 Darwin/16.3.0',
}
ITEM_PIPELINES = {
   "douyu3.pipelines.Douyu3Pipeline": 1,
}
IMAGE_STORE = "/Users/enritami/desktop/SearchEngineer/douyu3/Images"

错误输出是ITEM_PIPELINES中没有 enter image description here

1 个答案:

答案 0 :(得分:0)

settings.py中的IMAGE_STORE应定义为IMAGES_STORE