Selenium webdriver 在 firefox profile.setppreferences 中禁用 Web



如何在火狐中禁用WebRTC检测"media.peerconnection.enabled" using Selenium webdriver

这是代码

 from selenium.webdriver.common.proxy import *
 from selenium import webdriver
 from selenium.webdriver.common.proxy import Proxy, ProxyType
 from time import sleep
profile = webdriver.FirefoxProfile() 
profile.set_preference( "general.useragent.override", tax )
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", "xx.xx.xx.xx")
profile.set_preference("network.proxy.http_port", 3128)
profile.set_preference("media.peerconnection.enabled", "false")
profile.update_preferences()
driver = webdriver.Firefox(profile)
driver.implicitly_wait(10)
print "url: "
driver.get('http://www.example.com')

profile.set_preference("media.peerconnection.enabled", "false")剂量仅在我手动设置时才有效如何使用硒做到这一点

我认为您必须按如下方式使用它:

 from selenium.webdriver.common.proxy import *
 from selenium import webdriver
 from selenium.webdriver.common.proxy import Proxy, ProxyType
 from time import sleep
 # init profile
 profile = webdriver.FirefoxProfile() 
 # set proxy and other prefs.
 profile.set_preference("network.proxy.type", 1)
 profile.set_preference("network.proxy.http", "xx.xx.xx.xx")
 profile.set_preference("network.proxy.http_port", 3128)
 # update to profile. you can do it repeated. FF driver will take it.
 profile.update_preferences()
 # You would also like to block flash 
 profile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so',False)
 profile.set_preference("media.peerconnection.enabled", False)
 # save to FF profile
 profile.update_preferences()
 driver = webdriver.Firefox(profile)
 driver.get('http://www.google.com')
 :
 :

AFAIK,您的代码中的问题是,Firefox 配置文件无法将字符串类型转换为布尔值。您尝试设置的这些首选项是布尔值,并且您尝试使用字符串"false"对其进行设置。请注意 False 的大写在 python 中是可以接受的。您也可以在 Firefox 配置文件目录中参考首选项.js。它将显示给定的火狐实例的所有设置首选项。

还要检查硒和火狐版本的兼容性。

最新更新