使用和随机化代理 [英] Using and Randomizing Proxies

查看:92
本文介绍了使用和随机化代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道您将如何为每个请求设置特定的代理?!

I'm just wondering how you would go about setting a specific proxy for each request?!

以下块引用是文档对此进行了说明.此外,文档仅提供Java的示例...

The following block quote is the only thing the documentation says about this. Also, the documentation only provides an example for Java...

Firefox 48及更高版本-GeckoDriver
Firefox在配置文件中维护其代理配置.您可以在配置文件中预设代理并使用该Firefox配置文件,也可以在快速创建的配置文件中对其进行设置,如以下示例所示.使用GeckoDriver,必须通过所需的功能传递代理.

Firefox version 48 and newer - GeckoDriver
Firefox maintains its proxy configuration in a profile. You can preset the proxy in a profile and use that Firefox Profile or you can set it on profile that is created on the fly as is shown in the following example. With GeckoDriver the proxy has to be passed through the required capabilities.

任何建议将不胜感激!

推荐答案

通常,如果我使用含硒的代理,我更喜欢一些易于阅读和理解的东西

usually if I am using proxies with selenium i prefer something a little simple to read and understand

class Properties:
    def __init__(self):
        self.options = Options()
        self.options.headless = True
        self.options.add_argument("ignore-certificate-errors")
        self.options.add_argument("--proxy-server=http://xxx.xxx.xx.54:xx28") #sets a proxy
        self.driver = webdriver.Chrome(options=self.options)

我倾向于从提供免费代理的网站" 中获得几种不同的代理,并对其进行测试,那些不会出错的代理将它们存储在列表或文件中并在初始化硒类时对其进行迭代.硒起作用的是哪一个起作用,如果硒被阻塞,则还有其他几种可供选择.我通过抓取此类站点并将它们存储在计算机中的文件中来获取代理,因此下次我想要一个有效的代理服务器时,不必回到该站点.

What i tend to do is get several different proxies from 'sites that offer free proxies' and test them out, the ones that don't throw an error i store them in a list or file and iterate over them while initializing the selenium class. Which ever one works is the one selenium runs on, if it gets blocked there are several more to pick from. I pull proxies by scraping such sites and storing them in a file on my computer so i do not have to go back to the site the next time i want a working proxy.

这篇关于使用和随机化代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆