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


Python ProxyList.size方法代码示例

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


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

示例1: Grab

# 需要导入模块: from grab.proxylist import ProxyList [as 别名]
# 或者: from grab.proxylist.ProxyList import size [as 别名]

#.........这里部分代码省略.........
        """
        Go to ``url``

        Args:
            :url: could be absolute or relative. If relative then t will be
            appended to the absolute URL of previous request.
        """

        return self.request(url=url, **kwargs)

    def download(self, url, location, **kwargs):
        """
        Fetch document located at ``url`` and save to to ``location``.
        """

        doc = self.go(url, **kwargs)
        with open(location, 'wb') as out:
            out.write(doc.body)
        return len(doc.body)

    def prepare_request(self, **kwargs):
        """
        Configure all things to make real network request.
        This method is called before doing real request via
        transport extension.
        """

        if self.transport is None:
            self.setup_transport(self.transport_param)
        self.reset()
        self.request_counter = next(REQUEST_COUNTER)
        if kwargs:
            self.setup(**kwargs)
        if self.proxylist.size() and self.config['proxy_auto_change']:
            self.change_proxy()
        self.request_method = self.detect_request_method()
        self.transport.process_config(self)

    def log_request(self, extra=''):
        """
        Send request details to logging system.
        """

        # pylint: disable=no-member
        thread_name = threading.currentThread().getName().lower()
        # pylint: enable=no-member
        if thread_name == 'mainthread':
            thread_name = ''
        else:
            thread_name = '-%s' % thread_name

        if self.config['proxy']:
            if self.config['proxy_userpwd']:
                auth = ' with authorization'
            else:
                auth = ''
            proxy_info = ' via %s proxy of type %s%s' % (
                self.config['proxy'], self.config['proxy_type'], auth)
        else:
            proxy_info = ''
        if extra:
            extra = '[%s] ' % extra
        logger_network.debug(
            '[%s%s] %s%s %s%s',
            ('%02d' % self.request_counter
             if self.request_counter is not None else 'NA'),
开发者ID:lorien,项目名称:grab,代码行数:70,代码来源:base.py

示例2: Grab

# 需要导入模块: from grab.proxylist import ProxyList [as 别名]
# 或者: from grab.proxylist.ProxyList import size [as 别名]

#.........这里部分代码省略.........

    def go(self, url, **kwargs):
        """
        Go to ``url``

        Args:
            :url: could be absolute or relative. If relative then t will be
            appended to the absolute URL of previous request.
        """

        return self.request(url=url, **kwargs)

    def download(self, url, location, **kwargs):
        """
        Fetch document located at ``url`` and save to to ``location``.
        """

        doc = self.go(url, **kwargs)
        with open(location, 'wb') as out:
            out.write(doc.body)
        return len(doc.body)

    def prepare_request(self, **kwargs):
        """
        Configure all things to make real network request.
        This method is called before doing real request via
        transport extension.
        """

        self.reset()
        self.request_counter = next(REQUEST_COUNTER)
        if kwargs:
            self.setup(**kwargs)
        if self.proxylist.size() and self.config['proxy_auto_change']:
            self.change_proxy()
        self.request_method = self.detect_request_method()
        self.transport.process_config(self)

    def log_request(self, extra=''):
        """
        Send request details to logging system.
        """

        thread_name = threading.currentThread().getName().lower()
        if thread_name == 'mainthread':
            thread_name = ''
        else:
            thread_name = '-%s' % thread_name

        if self.config['proxy']:
            if self.config['proxy_userpwd']:
                auth = ' with authorization'
            else:
                auth = ''
            proxy_info = ' via %s proxy of type %s%s' % (
                self.config['proxy'], self.config['proxy_type'], auth)
        else:
            proxy_info = ''
        if extra:
            extra = '[%s] ' % extra
        logger_network.debug('[%02d%s] %s%s %s%s',
                             self.request_counter, thread_name,
                             extra, self.request_method or 'GET',
                             self.config['url'], proxy_info)

    def request(self, **kwargs):
开发者ID:noscripter,项目名称:grab,代码行数:70,代码来源:base.py

示例3: test_web_proxy_source

# 需要导入模块: from grab.proxylist import ProxyList [as 别名]
# 或者: from grab.proxylist.ProxyList import size [as 别名]
 def test_web_proxy_source(self):
     plist = ProxyList()
     self.server.response['data'] = DEFAULT_PLIST_DATA
     plist.load_url(self.server.get_url())
     self.assertEqual(2, plist.size())
开发者ID:lorien,项目名称:grab,代码行数:7,代码来源:proxy.py

示例4: test_file_proxy_source

# 需要导入模块: from grab.proxylist import ProxyList [as 别名]
# 或者: from grab.proxylist.ProxyList import size [as 别名]
 def test_file_proxy_source(self):
     with temp_file() as path:
         plist = ProxyList()
         self.generate_plist_file(path)
         plist.load_file(path)
         self.assertEqual(2, plist.size())
开发者ID:lorien,项目名称:grab,代码行数:8,代码来源:proxy.py

示例5: test_basic

# 需要导入模块: from grab.proxylist import ProxyList [as 别名]
# 或者: from grab.proxylist.ProxyList import size [as 别名]
 def test_basic(self):
     plist = ProxyList()
     self.assertEqual(0, plist.size())
开发者ID:lorien,项目名称:grab,代码行数:5,代码来源:proxy.py

示例6: test_file_proxy_source

# 需要导入模块: from grab.proxylist import ProxyList [as 别名]
# 或者: from grab.proxylist.ProxyList import size [as 别名]
 def test_file_proxy_source(self):
     pl = ProxyList()
     path = self.generate_plist_file()
     pl.load_file(path)
     self.assertEqual(2, pl.size())
开发者ID:Michael-F-Bryan,项目名称:grab,代码行数:7,代码来源:proxy.py


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