конвейер scrapy xmlitemexporter получает имя файла в качестве ввода - PullRequest
0 голосов
/ 12 марта 2020

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

Как я могу получить конвейер xmlitemexporter, получив имя файла в качестве ввода. Например, когда мы запускаем spider как: scrapy crawl spidername -o filename. xml

Пожалуйста, проверьте мой код конвейера:

import scrapy
from scrapy.exporters import XmlItemExporter

class AndorrapPipeline(object):
    def __init__(self):
        self.file = open("filename.xml", 'wb')
        #want this filename from the command scrapy crawl spidername -o filename.xml
        self.exporter = XmlItemExporter(self.file,root_element="root",item_element="property",encoding='utf-8')
        self.exporter.start_exporting()

    def close_spider(self, spider):
        self.exporter.finish_exporting()
        self.file.close()

    def process_item(self, item, spider):
        self.exporter.export_item(item)
        return item
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...