【问题标题】:Scrapy specify default shell for `scrapy shell`Scrapy 为 `scrapy shell` 指定默认 shell
【发布时间】:2023-02-26 05:40:48
【问题描述】:

根据它的文档,Scrapy 将使用 ipython 如果它已经安装在用户的系统中。是否可以安装 ipython 但仍然通过在 scrapy.cfg 中指定 shell 字段来指示 Scrapy 使用默认的 python shell?

目前,无论我在该字段中指定什么,Scrapy 都使用 ipython(即使它被省略)

【问题讨论】:

    标签: python web-scraping scrapy


    【解决方案1】:

    根据 scrapy 文档:

    通过 Scrapy 的设置,您可以将其配置为使用 ipython、bpython 或标准 python shell 中的任何一个,无论安装了哪个。这是通过设置 SCRAPY_PYTHON_SHELL 环境变量来完成的;或者在你的 scrapy.cfg 中定义它:

    默认的scrapy.cfg 如下所示:

    # Automatically created by: scrapy startproject
    #
    # For more information about the [deploy] section see:
    # https://scrapyd.readthedocs.io/en/latest/deploy.html
    
    [settings]
    default = projectname.settings
    
    
    [deploy]
    #url = http://localhost:6800/
    project = projectname
    

    因此,为了指定要使用的 shell,您需要将其添加到 settings 标头下,如下所示。

    # Automatically created by: scrapy startproject
    #
    # For more information about the [deploy] section see:
    # https://scrapyd.readthedocs.io/en/latest/deploy.html
    
    [settings]
    default = projectname.settings
    shell = python
    
    [deploy]
    #url = http://localhost:6800/
    project = projectname
    

    我已经测试并确认这有效并且确实使用了标准的 python shell,即使我在同一环境中安装了 ipython。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-24
      • 2016-02-07
      相关资源
      最近更新 更多