我将Selenium与Python Chrome webdriver一起使用。在我的代码中,我使用了:
driver = webdriver.Chrome(executable_path = PATH_TO_WEBDRIVER)
将webdriver指向webdriver可执行文件。是否可以将webdriver指向Chrome浏览器二进制文件?
在https://sites.google.com/a/chromium.org/chromedriver/capabilities中,它们具有以下内容(我认为这是我想要的内容):
ChromeOptions options = new ChromeOptions(); options.setBinary("/path/to/other/chrome/binary");
任何人都有Python的范例吗?
您可以使用以下几种方法通过使用Python的 ChromeDriver 设置Chrome浏览器二进制位置:
from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.binary_location = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe" driver = webdriver.Chrome(chrome_options=options, executable_path="C:/Utility/BrowserDrivers/chromedriver.exe", ) driver.get('http://google.com/')
from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities cap = DesiredCapabilities.CHROME cap = {'binary_location': "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"} driver = webdriver.Chrome(desired_capabilities=cap, executable_path="C:\\Utility\\BrowserDrivers\\chromedriver.exe") driver.get('http://google.com/')
from selenium import webdriver import selenium.webdriver.chrome.service as service service = service.Service('C:\\Utility\\BrowserDrivers\\chromedriver.exe') service.start() capabilities = {'chrome.binary': "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"} driver = webdriver.Remote(service.service_url, capabilities) driver.get('http://www.google.com')