在PyCharm python控制台中复制scrapy shell功能

问题描述:

如何在PyCharm IPython控制台中运行scrapy shell仿真?我想保持从编辑器运行代码片段的能力Alt + Shift + E在PyCharm python控制台中复制scrapy shell功能

我把它通过运行下面的Python代码片段工作:

from scrapy.cmdline import execute 
import sys 
sys.argv = ['scrapy', 'shell', 'http://scrapy.org'] 
execute() 

如果您收到以下错误:

MultipleInstanceError: Multiple incompatible subclass instances of InteractiveShellEmbed are being created. 

,那么你必须添加到scrapy.cfg以下行:

shell=python 
+0

当我尝试使用这个方法时,我用'ipython'(我的首选shell)得到'MultipleInstanceError',即使用'shell = ipython'写成[docs](https://doc.scrapy.org/zh/latest/topics/ shell.html#configurations-the-shell),但是使用普通的shell就可以工作。 –

+0

另一个限制 - 不在远程解释器中工作 –

您在pycharm窗口底部有一个终端图标。

enter image description here

它会打开一个新的终端,您可以在其中运行scrapy shell

+1

问题不在于此。问题是:“如何在PyCharm ** python控制台**中运行'scrapy shell'?” –

+0

对不起,误会。从[官方文档](https://www.jetbrains.com/help/pycharm/loading-code-from-editor-into-console.html),没有任何内容表明这是可能的。我希望有人有答案。 –