コード例 #1
0
ファイル: shell.py プロジェクト: herberthamaral/scrapy
 def _start(self, url=None, request=None, response=None, spider=None):
     if url:
         self.fetch(url, spider)
     elif request:
         self.fetch(request, spider)
     elif response:
         request = response.request
         self.populate_vars(request.url, response, request, spider)
     if self.code:
         print eval(self.code, globals(), self.vars)
     else:
         start_python_console(self.vars)
コード例 #2
0
 def _start(self, url=None, request=None, response=None, spider=None):
     if url:
         self.fetch(url, spider)
     elif request:
         self.fetch(request, spider)
     elif response:
         request = response.request
         self.populate_vars(response, request, spider)
     else:
         self.populate_vars()
     if self.code:
         print eval(self.code, globals(), self.vars)
     else:
         start_python_console(self.vars)
コード例 #3
0
ファイル: shell.py プロジェクト: pyarnold/scrapy
 def start(self, url=None, request=None, response=None, spider=None):
     # disable accidental Ctrl-C key press from shutting down the engine
     signal.signal(signal.SIGINT, signal.SIG_IGN)
     if url:
         self.fetch(url, spider)
     elif request:
         self.fetch(request, spider)
     elif response:
         request = response.request
         self.populate_vars(response, request, spider)
     else:
         self.populate_vars()
     if self.code:
         print(eval(self.code, globals(), self.vars))
     else:
         start_python_console(self.vars)
コード例 #4
0
ファイル: shell.py プロジェクト: reprior123/TraderSoftwareRP
 def start(self, url=None, request=None, response=None, spider=None):
     # disable accidental Ctrl-C key press from shutting down the engine
     signal.signal(signal.SIGINT, signal.SIG_IGN)
     if url:
         self.fetch(url, spider)
     elif request:
         self.fetch(request, spider)
     elif response:
         request = response.request
         self.populate_vars(response, request, spider)
     else:
         self.populate_vars()
     if self.code:
         print(eval(self.code, globals(), self.vars))
     else:
         start_python_console(self.vars)
コード例 #5
0
ファイル: shell.py プロジェクト: bf96163/scrapy
 def start(self,
           url=None,
           request=None,
           response=None,
           spider=None,
           redirect=True):
     # disable accidental Ctrl-C key press from shutting down the engine
     signal.signal(signal.SIGINT, signal.SIG_IGN)
     if url:
         self.fetch(url, spider, redirect=redirect)  #有URL就爬URL
     elif request:
         self.fetch(request, spider)  # 有request 就爬request
     elif response:
         request = response.request
         self.populate_vars(response, request, spider)
     else:
         self.populate_vars()
     if self.code:
         print(eval(
             self.code, globals(),
             self.vars))  # eval就是将字符串 第一个参数是 字符串 第二个是globals 第三个是locals
     else:  #这里 如果没有传入code的话 这里从 环境变量和scrapy.cfg文件中读取和拿到想要的Pythonshell
         """
         Detect interactive shell setting in scrapy.cfg
         e.g.: ~/.config/scrapy.cfg or ~/.scrapy.cfg
         [settings]
         # shell can be one of ipython, bpython or python;
         # to be used as the interactive python console, if available.
         # (default is ipython, fallbacks in the order listed above)
         shell = python
         """
         cfg = get_config()  #scrapy.cfg的配置
         section, option = 'settings', 'shell'
         env = os.environ.get('SCRAPY_PYTHON_SHELL')
         shells = []
         if env:
             shells += env.strip().lower().split(',')
         elif cfg.has_option(section, option):
             shells += [cfg.get(section, option).strip().lower()]
         else:  # try all by default
             shells += DEFAULT_PYTHON_SHELLS.keys()
         # always add standard shell as fallback
         shells += ['python']
         start_python_console(self.vars,
                              shells=shells,
                              banner=self.vars.pop('banner', ''))  #开启shell
コード例 #6
0
ファイル: shell.py プロジェクト: kongshuaifu/debug_scrapy
 def start(self,
           url=None,
           request=None,
           response=None,
           spider=None,
           redirect=True):
     # disable accidental Ctrl-C key press from shutting down the engine
     signal.signal(signal.SIGINT, signal.SIG_IGN)
     if url:
         self.fetch(url, spider, redirect=redirect)
     elif request:
         self.fetch(request, spider)
     elif response:
         request = response.request
         self.populate_vars(response, request, spider)
     else:
         self.populate_vars()
     if self.code:
         print(eval(self.code, globals(), self.vars))
     else:
         """
         Detect interactive shell setting in scrapy.cfg
         e.g.: ~/.config/scrapy.cfg or ~/.scrapy.cfg
         [settings]
         # shell can be one of ipython, bpython or python;
         # to be used as the interactive python console, if available.
         # (default is ipython, fallbacks in the order listed above)
         shell = python
         """
         cfg = get_config()
         section, option = 'settings', 'shell'
         env = os.environ.get('SCRAPY_PYTHON_SHELL')
         shells = []
         if env:
             shells += env.strip().lower().split(',')
         elif cfg.has_option(section, option):
             shells += [cfg.get(section, option).strip().lower()]
         else:  # try all by default
             shells += DEFAULT_PYTHON_SHELLS.keys()  # 获取所有的python交互类型
         # always add standard shell as fallback
         shells += ['python']  # 总是追加标准的python类型在末尾
         # 根据指定的shell类型,开启指定的shell界面
         start_python_console(self.vars,
                              shells=shells,
                              banner=self.vars.pop('banner', ''))
コード例 #7
0
ファイル: shell.py プロジェクト: runt18/scrapy
 def start(self, url=None, request=None, response=None, spider=None):
     # disable accidental Ctrl-C key press from shutting down the engine
     signal.signal(signal.SIGINT, signal.SIG_IGN)
     if url:
         self.fetch(url, spider)
     elif request:
         self.fetch(request, spider)
     elif response:
         request = response.request
         self.populate_vars(response, request, spider)
     else:
         self.populate_vars()
     if self.code:
         print(eval(self.code, globals(), self.vars))
     else:
         """
         Detect interactive shell setting in scrapy.cfg
         e.g.: ~/.config/scrapy.cfg or ~/.scrapy.cfg
         [settings]
         # shell can be one of ipython, bpython or python;
         # to be used as the interactive python console, if available.
         # (default is ipython, fallbacks in the order listed above)
         shell = python
         """
         cfg = get_config()
         section, option = 'settings', 'shell'
         env = os.environ.get('SCRAPY_PYTHON_SHELL')
         shells = []
         if env:
             shells += env.strip().lower().split(',')
         elif cfg.has_option(section, option):
             shells += [cfg.get(section, option).strip().lower()]
         else:  # try all by default
             shells += DEFAULT_PYTHON_SHELLS.keys()
         # always add standard shell as fallback
         shells += ['python']
         start_python_console(self.vars, shells=shells,
                              banner=self.vars.pop('banner', ''))
コード例 #8
0
ファイル: shell.py プロジェクト: zanachka/dscrapy
from scrapy.utils import console

from scrapy_master import scrapyd_utils
from scrapy_master import client
from scrapy_master import settings

console.start_python_console(namespace={
    'scrapyd_utils': scrapyd_utils,
    'client': client,
    'settings': settings,
},
                             shells=['ipython'])