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


Python ProxyList.get_next_proxy方法代码示例

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


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

示例1: test_get_next_proxy

# 需要导入模块: from grab.proxylist import ProxyList [as 别名]
# 或者: from grab.proxylist.ProxyList import get_next_proxy [as 别名]
 def test_get_next_proxy(self):
     pl = ProxyList()
     path = self.generate_plist_file('foo:1\nbar:1')
     pl.load_file(path)
     self.assertEqual(pl.get_next_proxy().host, 'foo')
     self.assertEqual(pl.get_next_proxy().host, 'bar')
     self.assertEqual(pl.get_next_proxy().host, 'foo')
     pl.load_file(path)
     self.assertEqual(pl.get_next_proxy().host, 'foo')
开发者ID:Michael-F-Bryan,项目名称:grab,代码行数:11,代码来源:proxy.py

示例2: test_get_next_proxy

# 需要导入模块: from grab.proxylist import ProxyList [as 别名]
# 或者: from grab.proxylist.ProxyList import get_next_proxy [as 别名]
 def test_get_next_proxy(self):
     with temp_file() as path:
         plist = ProxyList()
         self.generate_plist_file(path, 'foo:1\nbar:1')
         plist.load_file(path)
         self.assertEqual(plist.get_next_proxy().host, 'foo')
         self.assertEqual(plist.get_next_proxy().host, 'bar')
         self.assertEqual(plist.get_next_proxy().host, 'foo')
         plist.load_file(path)
         self.assertEqual(plist.get_next_proxy().host, 'foo')
开发者ID:lorien,项目名称:grab,代码行数:12,代码来源:proxy.py

示例3: Grab

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

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

        self.reset()
        if isinstance(content, six.text_type):
            raise error.GrabMisuseError('Method `setup_document` accepts only '
                                        'byte string in `content` argument.')

        # Configure Document instance
        doc = Document(grab=self)
        doc.body = content
        doc.status = ''
        doc.head = b'HTTP/1.1 200 OK\r\n\r\n'
        doc.parse(charset=kwargs.get('document_charset'))
        doc.code = 200
        doc.total_time = 0
        doc.connect_time = 0
        doc.name_lookup_time = 0
        doc.url = ''

        for key, value in kwargs.items():
            setattr(doc, key, value)

        self.doc = doc

    def change_proxy(self, random=True):
        """
        Set random proxy from proxylist.
        """

        if self.proxylist.size():
            if random:
                proxy = self.proxylist.get_random_proxy()
            else:
                proxy = self.proxylist.get_next_proxy()
            self.setup(proxy=proxy.get_address(),
                       proxy_userpwd=proxy.get_userpwd(),
                       proxy_type=proxy.proxy_type)
        else:
            logger.debug('Proxy list is empty')

    #
    # Private methods
    #

    @classmethod
    def common_headers(cls):
        """
        Build headers which sends typical browser.
        """

        return {
            'Accept': 'text/xml,application/xml,application/xhtml+xml'
                      ',text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.%d'
                      % randint(2, 5),
            'Accept-Language': 'en-us,en;q=0.%d' % (randint(5, 9)),
            'Accept-Charset': 'utf-8,windows-1251;q=0.7,*;q=0.%d'
                              % randint(5, 7),
            'Keep-Alive': '300',
        }

    def save_dumps(self):
        # pylint: disable=no-member
        thread_name = threading.currentThread().getName().lower()
        # pylint: enable=no-member
        if thread_name == 'mainthread':
            thread_name = ''
开发者ID:lorien,项目名称:grab,代码行数:70,代码来源:base.py

示例4: Grab

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

#.........这里部分代码省略.........
        doc.status = ''
        doc.head = ''
        doc.parse(charset=kwargs.get('document_charset'))
        doc.code = 200
        doc.total_time = 0
        doc.connect_time = 0
        doc.name_lookup_time = 0
        doc.url = ''

        for key, value in kwargs.items():
            setattr(doc, key, value)

        self.doc = doc

    def change_proxy(self):
        """
        Set random proxy from proxylist.
        """

        if self.proxylist.size():
            proxy = self.proxylist.get_random_proxy()
            self.setup(proxy=proxy.get_address(),
                       proxy_userpwd=proxy.get_userpwd(),
                       proxy_type=proxy.proxy_type)
        else:
            logger.debug('Proxy list is empty')

    def use_next_proxy(self):
        """
        Set next proxy from proxylist.
        """

        if self.proxylist.size():
            proxy = self.proxylist.get_next_proxy()
            self.setup(proxy=proxy.get_address(),
                       proxy_userpwd=proxy.get_userpwd(),
                       proxy_type=proxy.proxy_type)
        else:
            logger.debug('Proxy list is empty')

    """
    Private methods
    """

    def common_headers(self):
        """
        Build headers which sends typical browser.
        """

        return {
            'Accept': 'text/xml,application/xml,application/xhtml+xml'
                      ',text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.%d'
                      % randint(2, 5),
            'Accept-Language': 'en-us,en;q=0.%d' % (randint(5, 9)),
            'Accept-Charset': 'utf-8,windows-1251;q=0.7,*;q=0.%d'
                              % randint(5, 7),
            'Keep-Alive': '300',
            'Expect': '',
        }

    def save_dumps(self):
        if self.config['log_dir']:
            thread_name = threading.currentThread().getName().lower()
            if thread_name == 'mainthread':
                thread_name = ''
            else:
开发者ID:noscripter,项目名称:grab,代码行数:70,代码来源:base.py


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