當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。