更新时间:2023-09-14 18:45:52
据我所知,只有两种方法来更改代理设置,一个通过配置文件),而另一个使用驱动程序的功能时,按照此处进行实例化。可悲的是,这些方法都没有做你想要的,因为它们都是在你创建驱动程序之前发生的。
我必须问,为什么要更改代理设置?我唯一可以想到的唯一解决方案就是将firefox指向可以在运行时更改的代理。我不确定,但这可能是与browsermob代理可能。
Is there any way to dynamically change the proxy being used by Firefox when using selenium webdriver?
Currently I have proxy support using a proxy profile but is there a way to change the proxy when the browser is alive and running?
My current code:
proxy = Proxy({
'proxyType': 'MANUAL',
'httpProxy': proxy_ip,
'ftpProxy': proxy_ip,
'sslProxy': proxy_ip,
'noProxy': '' # set this value as desired
})
browser = webdriver.Firefox(proxy=proxy)
Thanks in advance.
As far as I know there are only two ways to change the proxy setting, one via a profile (which you are using) and the other using the capabilities of a driver when you instantiate it as per here. Sadly neither of these methods do what you want as they both happen before as you create your driver.
I have to ask, why is it you want to change your proxy settings? The only solution I can esily think of is to point firefox to a proxy that you can change at runtime. I am not sure but that might be possible with browsermob-proxy.