scrapy shell url在iPython笔记本中返回SyntaxError

时间:2017-04-28 01:43:13

标签: scrapy ipython

在windows power shell中,我可以运行scrapy shell 'http://www.hao123.com'scrapy shell 'http://www.hao123.com 我可以运行ipython 我可以ipython而不是scrapy shell 'http://www.hao123.com' ipython then scrapy shell 'http://www.hao123.com 在ipython笔记本中,我也无法运行scrapy shell 'http://www.hao123.com'

scrapy shell 'http://www.hao123.com'
  File "<ipython-input-3-be4048c8f90b>", line 1
    scrapy shell 'http://www.hao123.com'
               ^
SyntaxError: invalid syntax

Ipython由anaconda安装,scrapy由pip,anaconda和pip安装在不同的文件中。 请帮帮我!

2 个答案:

答案 0 :(得分:0)

这不是ipython中的功能。 scrapy shell是一个命令,它自己的应用程序与ipython完全分开。

但是,您可以做两件事:

如果您有来自某个地方的Spider和Response对象,则可以使用scrapy.shell.inspect_repsonse

from scrapy.shell import inspect_response
# You need a scrapy spider object that has crawler instance attached to it
some_spider = Spider()  
# you need response object
some_response = Response()  
inspect_response(some_spider, some_response)
# new ipython shell will be embedded, like one from scrapy shell command

否则你可以产生一个子进程:

import subprocess
subprocess.call('scrapy shell http://stackoverflow.com', shell=True)
# new ipython shell will be embedded, like one from scrapy shell command

答案 1 :(得分:0)

如果您在Windows 7上使用Anaconda。 关注:环境 - &gt; root - &gt;打开终端。然后你可以写:

  

scrapy shell&#39; http://www.hao123.com&#39;

相关问题