2017-02-03 48 views
1

如何停用WebRTC檢測在Firefox 「media.peerconnection.enabled」 使用硒的webdriver硒的webdriver停用WebRTC檢測在Firefox profile.setpreference

這是代碼

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」)只有在我手動設置的情況下才起作用 Selenium如何做到這一點

回答

0

我認爲你必須如下使用它:

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') 
: 
: 

據我所知,在問題的代碼,Firefox的配置文件不能強制轉換的字符串爲布爾值。你試圖設置的這些preferenece是布爾值,你試圖用字符串「false」來設置它。 請注意False的帽子在python中可以接受。您也可以參考Firefox配置文件目錄中的prefs.js。它會顯示給定的Firefox實例的所有設置首選項。

也檢查硒和firefox版本的兼容性。