在硒期间更改代理服务器 [英] Changing the proxy server during Selenium

查看:457
本文介绍了在硒期间更改代理服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一切正常

fp = webdriver.FirefoxProfile()
fp.set_preference("network.proxy.type", 1)
fp.set_preference("network.proxy.http", PROXY_HOST)
fp.set_preference("network.proxy.http_port", int(PROXY_PORT))
fp.update_preferences()
driver = webdriver.Firefox(firefox_profile=fp)

但是,如果已经创建了驱动程序,则无法安装代理. 它不起作用

But if the driver has already been created, the proxy can not install. It does not work

driver = webdriver.Firefox()
driver.profile.set_preference("network.proxy.type", 1)
driver.profile.set_preference("network.proxy.http", PROXY_HOST)
driver.profile.set_preference("network.proxy.http_port", int(PROXY_PORT))
driver.profile.update_preferences()

也是.

 driver = webdriver.Firefox()
 driver.firefox_profile.set_preference("network.proxy.type", 1)
 driver.firefox_profile.set_preference("network.proxy.http", PROXY_HOST)
 driver.firefox_profile.set_preference("network.proxy.http_port", int(PROXY_PORT))
 driver.firefox_profile.update_preferences()

为什么?不能理解. 我做错了什么?

Why? Can not understand. I'm doing something wrong?

推荐答案

在Firefox中使用WebDriver时,使用配置文件是一次性的事情.驱动程序启动浏览器时,它将配置文件对象写入磁盘,然后启动浏览器可执行文件.在那之后,浏览器没有任何机制可以读取对WebDriver配置文件对象的任何进一步的更改.要更改代理,必须在启动浏览器之前在配置文件中设置设置.

When using WebDriver with Firefox, the use of the profile is a one-time thing. When the driver launches the browser, it writes the profile object to disk, then starts the browser executable. After that point, there is no mechanism for the browser to read any further changes to the WebDriver profile object. To change the proxy, you have to set the settings in the profile before the browser is launched.

这篇关于在硒期间更改代理服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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