MCPcopy
hub / github.com/scrapy/scrapy / start

Method start

scrapy/shell.py:148–191  ·  view source on GitHub ↗
(
        self,
        url: str | None = None,
        request: Request | None = None,
        response: Response | None = None,
        spider: Spider | None = None,
        redirect: bool = True,
    )

Source from the content-addressed store, hash-verified

146 return self._inthread
147
148 def start(
149 self,
150 url: str | None = None,
151 request: Request | None = None,
152 response: Response | None = None,
153 spider: Spider | None = None,
154 redirect: bool = True,
155 ) -> None:
156 # disable accidental Ctrl-C key press from shutting down the engine
157 signal.signal(signal.SIGINT, signal.SIG_IGN)
158 if url:
159 self.fetch(url, spider, redirect=redirect)
160 elif request:
161 self.fetch(request, spider)
162 elif response:
163 request = response.request
164 self.populate_vars(response, request, spider)
165 else:
166 self.populate_vars()
167 if self.code:
168 print(eval(self.code, globals(), self.vars)) # noqa: S307
169 else:
170 # Detect interactive shell setting in scrapy.cfg
171 # e.g.: ~/.config/scrapy.cfg or ~/.scrapy.cfg
172 # [settings]
173 # # shell can be one of ipython, bpython or python;
174 # # to be used as the interactive python console, if available.
175 # # (default is ipython, fallbacks in the order listed above)
176 # shell = python
177 cfg = get_config()
178 section, option = "settings", "shell"
179 env = os.environ.get("SCRAPY_PYTHON_SHELL")
180 shells = []
181 if env:
182 shells += env.strip().lower().split(",")
183 elif cfg.has_option(section, option):
184 shells += [cfg.get(section, option).strip().lower()]
185 else: # try all by default
186 shells += DEFAULT_PYTHON_SHELLS.keys()
187 # always add standard shell as fallback
188 shells += ["python"]
189 start_python_console(
190 self.vars, shells=shells, banner=self.vars.pop("banner", "")
191 )
192
193 async def _schedule(self, request: Request, spider: Spider | None) -> Response:
194 """Send the request to the engine, wait for the result.

Callers 2

runMethod · 0.95
inspect_responseFunction · 0.45

Calls 7

fetchMethod · 0.95
populate_varsMethod · 0.95
get_configFunction · 0.90
start_python_consoleFunction · 0.90
keysMethod · 0.80
getMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected