当前位置: 首页>>代码示例>>Python>>正文


Python BaseSpider.set_crawler方法代码示例

本文整理汇总了Python中scrapy.spider.BaseSpider.set_crawler方法的典型用法代码示例。如果您正苦于以下问题:Python BaseSpider.set_crawler方法的具体用法?Python BaseSpider.set_crawler怎么用?Python BaseSpider.set_crawler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scrapy.spider.BaseSpider的用法示例。


在下文中一共展示了BaseSpider.set_crawler方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_defaults_spider_mw

# 需要导入模块: from scrapy.spider import BaseSpider [as 别名]
# 或者: from scrapy.spider.BaseSpider import set_crawler [as 别名]
 def get_defaults_spider_mw(self):
     crawler = get_crawler()
     spider = BaseSpider('foo')
     spider.set_crawler(crawler)
     defaults = dict([(k, [v]) for k, v in \
         crawler.settings.get('DEFAULT_REQUEST_HEADERS').iteritems()])
     return defaults, spider, DefaultHeadersMiddleware()
开发者ID:Aaron1011,项目名称:oh-mainline,代码行数:9,代码来源:test_downloadermiddleware_defaultheaders.py

示例2: ManagerTestCase

# 需要导入模块: from scrapy.spider import BaseSpider [as 别名]
# 或者: from scrapy.spider.BaseSpider import set_crawler [as 别名]
class ManagerTestCase(TestCase):

    settings_dict = None

    def setUp(self):
        self.crawler = get_crawler(self.settings_dict)
        self.spider = BaseSpider('foo')
        self.spider.set_crawler(self.crawler)
        self.mwman = DownloaderMiddlewareManager.from_crawler(self.crawler)
        # some mw depends on stats collector
        self.crawler.stats.open_spider(self.spider)
        return self.mwman.open_spider(self.spider)

    def tearDown(self):
        self.crawler.stats.close_spider(self.spider, '')
        return self.mwman.close_spider(self.spider)

    def _download(self, request, response=None):
        """Executes downloader mw manager's download method and returns
        the result (Request or Response) or raise exception in case of
        failure.
        """
        if not response:
            response = Response(request.url)

        def download_func(**kwargs):
            return response

        dfd = self.mwman.download(download_func, request, self.spider)
        # catch deferred result and return the value
        results = []
        dfd.addBoth(results.append)
        self._wait(dfd)
        ret = results[0]
        if isinstance(ret, Failure):
            ret.raiseException()
        return ret
开发者ID:00gpowe,项目名称:scrapy,代码行数:39,代码来源:test_downloadermiddleware.py

示例3: get_spider_and_mw

# 需要导入模块: from scrapy.spider import BaseSpider [as 别名]
# 或者: from scrapy.spider.BaseSpider import set_crawler [as 别名]
 def get_spider_and_mw(self, default_useragent):
     crawler = get_crawler({'USER_AGENT': default_useragent})
     spider = BaseSpider('foo')
     spider.set_crawler(crawler)
     return spider, UserAgentMiddleware()
开发者ID:Aaron1011,项目名称:oh-mainline,代码行数:7,代码来源:test_downloadermiddleware_useragent.py

示例4: get_request_spider_mw

# 需要导入模块: from scrapy.spider import BaseSpider [as 别名]
# 或者: from scrapy.spider.BaseSpider import set_crawler [as 别名]
 def get_request_spider_mw(self):
     crawler = get_crawler()
     spider = BaseSpider('foo')
     spider.set_crawler(crawler)
     request = Request('http://scrapytest.org/')
     return request, spider, DownloadTimeoutMiddleware.from_crawler(crawler)
开发者ID:1012,项目名称:scrapy,代码行数:8,代码来源:test_downloadermiddleware_downloadtimeout.py


注:本文中的scrapy.spider.BaseSpider.set_crawler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。