使用scrapy的telnet功能远程管理scrapy运行
用法
telnet <IP_ADDR> <PORT>
官方文档
https://doc.scrapy.org/en/latest/topics/telnetconsole.html
简单使用
crawler            the Scrapy Crawler (scrapy.crawler.Crawler object)
engine Crawler.engine attribute
spider the active spider
slot the engine slot
extensions the Extension Manager (Crawler.extensions attribute)
stats the Stats Collector (Crawler.stats attribute)
settings the Scrapy settings object (Crawler.settings attribute)
est print a report of the engine status
prefs for memory debugging (see Debugging memory leaks)
p a shortcut to the pprint.pprint function
hpy for memory debugging (see Debugging memory leaks)
参数设置
TELNETCONSOLE_PORT      Default: [6023, 6073]

TELNETCONSOLE_HOST      Default: '127.0.0.1'
telnet源码
"""
Scrapy Telnet Console extension See documentation in docs/topics/telnetconsole.rst
""" import pprint
import logging from twisted.internet import protocol
try:
from twisted.conch import manhole, telnet
from twisted.conch.insults import insults
TWISTED_CONCH_AVAILABLE = True
except ImportError:
TWISTED_CONCH_AVAILABLE = False from scrapy.exceptions import NotConfigured
from scrapy import signals
from scrapy.utils.trackref import print_live_refs
from scrapy.utils.engine import print_engine_status
from scrapy.utils.reactor import listen_tcp try:
import guppy
hpy = guppy.hpy()
except ImportError:
hpy = None logger = logging.getLogger(__name__) # signal to update telnet variables
# args: telnet_vars
update_telnet_vars = object() class TelnetConsole(protocol.ServerFactory): def __init__(self, crawler):
if not crawler.settings.getbool('TELNETCONSOLE_ENABLED'):
raise NotConfigured
if not TWISTED_CONCH_AVAILABLE:
raise NotConfigured
self.crawler = crawler
self.noisy = False
self.portrange = [int(x) for x in crawler.settings.getlist('TELNETCONSOLE_PORT')]
self.host = crawler.settings['TELNETCONSOLE_HOST']
self.crawler.signals.connect(self.start_listening, signals.engine_started)
self.crawler.signals.connect(self.stop_listening, signals.engine_stopped) @classmethod
def from_crawler(cls, crawler):
return cls(crawler) def start_listening(self):
self.port = listen_tcp(self.portrange, self.host, self)
h = self.port.getHost()
logger.debug("Telnet console listening on %(host)s:%(port)d",
{'host': h.host, 'port': h.port},
extra={'crawler': self.crawler}) def stop_listening(self):
self.port.stopListening() def protocol(self):
telnet_vars = self._get_telnet_vars()
return telnet.TelnetTransport(telnet.TelnetBootstrapProtocol,
insults.ServerProtocol, manhole.Manhole, telnet_vars) def _get_telnet_vars(self):
# Note: if you add entries here also update topics/telnetconsole.rst
telnet_vars = {
'engine': self.crawler.engine,
'spider': self.crawler.engine.spider,
'slot': self.crawler.engine.slot,
'crawler': self.crawler,
'extensions': self.crawler.extensions,
'stats': self.crawler.stats,
'settings': self.crawler.settings,
'est': lambda: print_engine_status(self.crawler.engine),
'p': pprint.pprint,
'prefs': print_live_refs,
'hpy': hpy,
'help': "This is Scrapy telnet console. For more info see: " \
"https://doc.scrapy.org/en/latest/topics/telnetconsole.html",
}
self.crawler.signals.send_catch_log(update_telnet_vars, telnet_vars=telnet_vars)
return telnet_vars

最新文章

  1. rabbimq连接问题处理
  2. Google one联合联发科,国内低端智能机方案怎么办?
  3. wxPython+Boa Constructor环境配置
  4. nginx 常用配置说明
  5. Android AIDL SERVICE 双向通信 详解
  6. 【Hadoop学习】Apache Hadoop ResourceManager HA
  7. 清除XCode缓存和生成文件
  8. IDF实验室-简单编程-特殊的日子 writeup
  9. Spring AOP实现方式四之注入式AspectJ切面【附源码】
  10. HDU 3899 简单树形DP
  11. POJ 2368 Buttons(巴什博弈变形)
  12. HTML5 02. 多媒体控件、拖拽事件、历史记录、web存储、应用程序缓存、地理定位、网络状态
  13. java web mysql 入门知识讲解
  14. Linux的软链接和硬链接
  15. MapReduce并行编程模型和框架
  16. .net带参数SQL语句的完整定义
  17. [SDOI2018] 旧试题
  18. element UI Cascader 级联选择器 编辑 修改 数组 路径 问题(转载)
  19. MySQL修改表、字段、库的字符集及字符集说明
  20. 初步了解学习将传统单机应用改造成Dubbo服务的过程

热门文章

  1. 【SAM】bzoj5084: hashit
  2. MySQL中一条SQL的加锁分析
  3. ubuntu18.04+win10解决时钟不同步办法
  4. python 类的使用
  5. day22-python之模块
  6. python中打印金字塔和九九乘法表的几种方法
  7. LeetCode(206) Reverse Linked List
  8. LOFTER 迁移
  9. JAVA 基础--开发环境Sublime Text 3 搭建
  10. I love you