python类exceptions()的实例源码

pipelines.py 文件源码 项目:pa-chong 作者: congminghaoxue 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def file_path(self, request, response=None, info=None):
        # start of deprecation warning block (can be removed in the future)
        def _warn():
            from scrapy.exceptions import ScrapyDeprecationWarning
            import warnings
            warnings.warn('file_key(url) method is deprecated, use '
                          'file_path(request, response=None, info=None)',
                          category=ScrapyDeprecationWarning, stacklevel=1)

        # check if called from file_key with url as first argument
        if not isinstance(request, scrapy.Request):
            _warn()
            url = request
        else:
            url = request.url

        # detect if file_key() method has been overridden
        if not hasattr(self.file_key, '_base'):
            _warn()
            return self.file_key(url)
        # end of deprecation warning block
        file_name = request.meta['title']
        # change to request.url after deprecation
        media_ext = url.split('/')[-1]
        return '%s' % file_name + media_ext.replace(' ', '_')
pipelines.py 文件源码 项目:pa-chong 作者: congminghaoxue 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def file_path(self, request, response=None, info=None):
        # start of deprecation warning block (can be removed in the future)
        def _warn():
            from scrapy.exceptions import ScrapyDeprecationWarning
            import warnings
            warnings.warn('file_key(url) method is deprecated, use '
                          'file_path(request, response=None, info=None)',
                          category=ScrapyDeprecationWarning, stacklevel=1)

        # check if called from file_key with url as first argument
        if not isinstance(request, scrapy.Request):
            _warn()
            url = request
        else:
            url = request.url

        # detect if file_key() method has been overridden
        if not hasattr(self.file_key, '_base'):
            _warn()
            return self.file_key(url)
        # end of deprecation warning block
        file_name = request.meta['title']
        # change to request.url after deprecation
        # media_ext = url.split('/')[-1]
        return '%s' % file_name # + media_ext.replace(' ', '_')
mongo.py 文件源码 项目:tobber 作者: fchamicapereira 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def open_spider(self, spider):

        try:
            self.client = pymongo.MongoClient(self.mongo_server, self.mongo_port, serverSelectionTimeoutMS=5)
            self.client.server_info()

        except pymongo.errors.ServerSelectionTimeoutError as err:
            print 'Mongo:', err
            raise scrapy.exceptions.CloseSpider('Can\'t connect to mongo database')

        self.db         = self.client[self.mongo_db]
        self.collection = self.db[self.mongo_collection]


问题


面经


文章

微信
公众号

扫码关注公众号