📜  Scrapy-Telnet控制台

📅  最后修改于: 2020-10-31 14:41:18             🧑  作者: Mango


描述

Telnet控制台是在Scrapy进程中运行的Python shell,用于检查和控制Scrapy运行的进程。

访问Telnet控制台

可以使用以下命令访问telnet控制台-

telnet localhost 6023

基本上,telnet控制台在TCP端口中列出,这在TELNETCONSOLE_PORT设置中进行了描述。

变数

下表中提供的一些默认变量用作快捷方式-

Sr.No Shortcut & Description
1

crawler

This refers to the Scrapy Crawler (scrapy.crawler.Crawler) object.

2

engine

This refers to Crawler.engine attribute.

3

spider

This refers to the spider which is active.

4

slot

This refers to the engine slot.

5

extensions

This refers to the Extension Manager (Crawler.extensions) attribute.

6

stats

This refers to the Stats Collector (Crawler.stats) attribute.

7

setting

This refers to the Scrapy settings object (Crawler.settings) attribute.

8

est

This refers to print a report of the engine status.

9

prefs

This refers to the memory for debugging.

10

p

This refers to a shortcut to the pprint.pprint function.

11

hpy

This refers to memory debugging.

例子

以下是使用Telnet控制台说明的一些示例。

暂停,恢复和停止Scrapy引擎

要暂停Scrapy引擎,请使用以下命令-

telnet localhost 6023
>>> engine.pause()
>>>

要恢复Scrapy引擎,请使用以下命令-

telnet localhost 6023
>>> engine.unpause()
>>>

要停止Scrapy引擎,请使用以下命令-

telnet localhost 6023
>>> engine.stop()
Connection closed by foreign host.

查看引擎状态

Telnet控制台使用est()方法检查Scrapy引擎的状态,如以下代码所示-

telnet localhost 6023
>>> est()
Execution engine status

time()-engine.start_time                        : 8.62972998619
engine.has_capacity()                           : False
len(engine.downloader.active)                   : 16
engine.scraper.is_idle()                        : False
engine.spider.name                              : followall
engine.spider_is_idle(engine.spider)            : False
engine.slot.closing                             : False
len(engine.slot.inprogress)                     : 16
len(engine.slot.scheduler.dqs or [])            : 0
len(engine.slot.scheduler.mqs)                  : 92
len(engine.scraper.slot.queue)                  : 0
len(engine.scraper.slot.active)                 : 0
engine.scraper.slot.active_size                 : 0
engine.scraper.slot.itemproc_size               : 0
engine.scraper.slot.needs_backout()             : False

Telnet控制台信号

您可以使用telnet控制台信号来添加,更新或删除telnet本地名称空间中的变量。要执行此操作,您需要在处理程序中添加telnet_vars字典。

scrapy.extensions.telnet.update_telnet_vars(telnet_vars)

参数-

telnet_vars (dict)

其中,dict是包含telnet变量的字典。

Telnet设置

下表显示了控制Telnet控制台行为的设置-

Sr.No Settings & Description Default Value
1

TELNETCONSOLE_PORT

This refers to port range for telnet console. If it is set to none, then the port will be dynamically assigned.

[6023, 6073]
2

TELNETCONSOLE_HOST

This refers to the interface on which the telnet console should listen.

‘127.0.0.1’