在Selenium期间更改代理服务器

2024-03-29 11:36:19 发布

您现在位置:Python中文网/ 问答频道 /正文

所以一切正常

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)

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

^{pr2}$

也是如此。在

 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()

为什么?无法理解。 我做错什么了?在


Tags: httphostporttypedrivernetworkfirefoxprofile
1条回答
网友
1楼 · 发布于 2024-03-29 11:36:19

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

相关问题 更多 >