【问题标题】:How to pass custom parameters(such as -o) to scrapy crawler如何将自定义参数(如-o)传递给scrapy爬虫
【发布时间】:2020-08-02 22:37:02
【问题描述】:

我目前正在开发 python2.7/Scrapy 1.8 项目。 我在 Docker 容器中工作并使用

launchable.py:

import scrapy
from scrapy.crawler import CrawlerProcess

from spiders import addonsimilartechSpider, similartechSpider

process = CrawlerProcess()
process.crawl(similartechSpider.SimilarTechSpider)
process.crawl(addonsimilartechSpider.AddonSimilarSpider)
process.start()

我以前是这样开始我的scrapy的:

scrapy crawl <nameofmyspider> -o output.xlsx

我安装了scrapy-xlsx 并使用它直到现在,现在我有了我的launchable.py 我不知道如何通过scrapy crawler(而不是spider)传递“自定义”参数。 我了解scrapy设置和蜘蛛设置之间的区别,所以:

process.crawl(similartechSpider.SimilarTechSpider, input='-o', first='test1.xlsx')

可能无法正常工作?

感谢您花时间回答这个问题。

【问题讨论】:

    标签: python-2.7 scrapy


    【解决方案1】:

    改用相应的 Scrapy 设置 (FEED_*)。

    您可以将它们作为dict 传递给CrawlerProcess

    【讨论】:

      【解决方案2】:
      CrawlerProcess(settings={
          'FEED_URI': 'output_file_name.xlsx',
          'FEED_EXPORTERS' : {'xlsx': 'scrapy_xlsx.XlsxItemExporter'},
      })
      

      【讨论】:

        猜你喜欢
        • 2017-12-28
        • 1970-01-01
        • 2023-03-25
        • 1970-01-01
        • 1970-01-01
        • 2019-12-27
        • 2021-08-18
        • 1970-01-01
        • 2016-11-20
        相关资源
        最近更新 更多