本文整理汇总了Python中scrapy.crawler.CrawlerRunner.stop方法的典型用法代码示例。如果您正苦于以下问题:Python CrawlerRunner.stop方法的具体用法?Python CrawlerRunner.stop怎么用?Python CrawlerRunner.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scrapy.crawler.CrawlerRunner
的用法示例。
在下文中一共展示了CrawlerRunner.stop方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CrawlerRunnerTest
# 需要导入模块: from scrapy.crawler import CrawlerRunner [as 别名]
# 或者: from scrapy.crawler.CrawlerRunner import stop [as 别名]
class CrawlerRunnerTest(unittest.TestCase):
def setUp(self):
self.crawler_runner = CrawlerRunner(Settings())
def tearDown(self):
return self.crawler_runner.stop()
@defer.inlineCallbacks
def test_populate_spidercls_settings(self):
spider_settings = {'TEST1': 'spider', 'TEST2': 'spider'}
project_settings = {'TEST1': 'project', 'TEST3': 'project'}
class CustomSettingsSpider(DefaultSpider):
custom_settings = spider_settings
self.crawler_runner.settings.setdict(project_settings,
priority='project')
d = self.crawler_runner.crawl(CustomSettingsSpider)
crawler = list(self.crawler_runner.crawlers)[0]
yield d
self.assertEqual(crawler.settings.get('TEST1'), 'spider')
self.assertEqual(crawler.settings.get('TEST2'), 'spider')
self.assertEqual(crawler.settings.get('TEST3'), 'project')
示例2: Bot
# 需要导入模块: from scrapy.crawler import CrawlerRunner [as 别名]
# 或者: from scrapy.crawler.CrawlerRunner import stop [as 别名]
class Bot(Resource):
spider = SlydSpider()
def __init__(self, settings, spec_manager):
# twisted base class is old-style so we cannot user super()
Resource.__init__(self)
self.spec_manager = spec_manager
settings.set('PLUGINS', [p['bot'] for p in settings.get('PLUGINS')])
self.runner = CrawlerRunner(settings)
log.msg("bot initialized", level=log.DEBUG)
def keep_spider_alive(self, spider):
raise DontCloseSpider("keeping it open")
def stop(self):
"""Stop the crawler"""
self.runner.stop()
log.msg("bot stopped", level=log.DEBUG)
示例3: Runner
# 需要导入模块: from scrapy.crawler import CrawlerRunner [as 别名]
# 或者: from scrapy.crawler.CrawlerRunner import stop [as 别名]
class Runner(object):
def __init__(self,*args,**kwargs):
configure_logging()
self.settings = get_project_settings()
self.runner = CrawlerRunner(self.settings)
def add(self,*a,**kw):
crawler = Crawler(BroadSpider,self.settings)
self.runner.crawl(crawler,*a,**kw)
def start(self):
d = self.runner.join()
d.addBoth(lambda _: reactor.stop())
reactor.run()
def stop(self):
self.runner.stop()
reactor.stop()