2013-03-01 27 views
10

Bunun için tüm günü araştırıyorum ve python için chromedriver uygulamasından şu anda mevcut bir çözüm bulunmuyor gibi görünüyor.Kromatlayıcıda selenyum için chrome.prefs python ile ayarlama

webdriver.Chrome() yöntemi kullanılarak belirli chrome.prefs (örneğin, profile.managed_default_content_settings.images = 2 gibi profil ayarları) nasıl ayarlanır?

Zaten başarıyla webdriver.ChromeOptions() üzerinden denedim. Java'da bunu başarmak için uygun işlevler vardır.

Ancak Python? Bu benim ... şu anda ne yapıyorum olduğunu

options = webdriver.ChromeOptions() 
    options.add_argument('--allow-running-insecure-content') 
    options.add_argument('--disable-web-security') 
    options.add_argument('--disk-cache-dir=/var/www/cake2.2.4/app/tmp/cache/selenium-chrome-cache') 
    options.add_argument('--no-referrers') 
    options.add_argument('--window-size=1003,719') 
    options.add_argument('--proxy-server=localhost:8118') 
    options.add_argument("'chrome.prefs': {'profile.managed_default_content_settings.images': 2}") 


    self.selenium = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver',chrome_options=options) 

cevap

3

Fix: chromeoptions nesne kaçınarak ve desiredcapabilities sözlüğe geri dönerek bir çözüm vardır

(kullanımdan kaldırıldı). Bazı sebeplerden dolayı selenyum kitaplığındaki webdriver.py boş bir chromeoptions sözlüğünü, istenen faydalar sözlüğüne ekler ve bu da işe yaramaz hale getirir. Yani

desired_capabilities.update(options.to_capabilities()) 

Sonra herkes bu soruya nedeniyle hayata ilişkin

CHROME = { 
"browserName": "chrome", 
     "version": "", 
     "platform": "ANY", 
     "javascriptEnabled": True, 
     "chrome.prefs": {"profile.managed_default_content_settings.images": 2}, 
     "proxy": { 
      "httpProxy":"localhost:8118", 
      "ftpProxy":None, 
      "sslProxy":None, 
      "noProxy":None, 
      "proxyType":"MANUAL", 
      "class":"org.openqa.selenium.Proxy", 
      "autodetect":False 
      }, 
     "chrome.switches": ["window-size=1003,719", "allow-running-insecure-content", "disable-web-security", "disk-cache-dir=/var/www/cake2.2.4/app/tmp/cache/selenium-chrome-cache", "no-referrers"], 
     } 


    self.selenium = webdriver.Chrome(desired_capabilities=CHROME) 
+0

Benzer sorun burada (Chrome'un indirme klasörünü değiştirmeye çalışıyorum). Kodunu denedim, ama bir şekilde benim için çalışmıyor. Webdriver.py dosyamdaki 'wanted_capabilities.update (options.to_capabilities())' satırı yorumlanmadı. Düşüncesi olan var mı? Başka çözümlerle karşılaştınız mı? – Parzival

+0

Hayır, sadece bu kadardı. bu çizgiyi buldunuz mu? desired_capabilities.update (options.to_capabilities()) – Jabb

+0

Yaptım. Yorum yapılmamıştı, o yüzden çalışmalıydı, ama bir şekilde yapmadı. Sonunda tamamen Chrome'dan vazgeçtim. – Parzival

3

Sadece küçük bir güncelleme chromedriver için istenen tüm yeteneklerini geçmek için bu kodu kullanmak webdriver.py uncomment hattına 54 gerekir.

yeni sürümler için aşağıdaki kod sorunsuz çalışır: chromedriver görüntüleri devre dışı bırakmak istediğiniz herkes için

options.add_experimental_option('prefs', {'download.default_directory':'C:\\temp'}) 
4

, aşağıdaki kod size yardımcı olabilir.

from selenium.webdriver.chrome.options import Options 
chrome_options = Options() 
chrome_options.add_experimental_option("prefs", {'profile.default_content_settings.images': 2}) 
driver = webdriver.Chrome(chrome_options=chrome_options) 
4

Bu geçerli sürüm 2.20 en az 2,15 ila son chromedriver sürümleri ile çalışır budur: Python sözdizimi ile mücadele herkes için

chrome_options = Options() 
chrome_options.add_experimental_option("prefs", {'profile.managed_default_content_settings.images': 2}) 
chrome = webdriver.Chrome('/path/to/chromedriver',chrome_options=chrome_options) 
chrome.get("https://google.com") 
1

, burada tam bir çalışma örneği. Chrome'un "Google Chrome'un bu site için şifrenizi kaydetmesini istiyor musunuz?" Özelliğini devre dışı bırakır. Komut istemi. Ayrıca bkz. WebDriver Chrome Browser: Avoid 'Do you want chrome to save your password' pop up.

from selenium import webdriver 
from selenium.webdriver.chrome.options import Options 
chrome_options = Options() 
chrome_options.add_experimental_option('prefs', { 
    'credentials_enable_service': False, 
    'profile': { 
     'password_manager_enabled': False 
    } 
}) 
driver = webdriver.Chrome(chrome_options=chrome_options) 
driver.get('https://google.com') 
İlgili konular