问题描述
我使用了Python Chrome浏览器的Selenium。
在我使用的代码中:
driver = webdriver.Chrome(executable_path = PATH_TO_WEBDRIVER)
code>
将webdriver指向webdriver可执行文件。有没有办法将webdriver指向Chrome浏览器的二进制文件?
在他们有以下内容(我认为它是我正在寻找的) :
ChromeOptions options = new ChromeOptions();
options.setBinary(/ path / to / other / chrome / binary);
任何人都有Python的例子吗?
以下是您的问题答案:您可以通过以下方式将Chrome浏览器二进制文件设置为Python中的chrome webdriver:
$ b 使用选项类:
来自selenium import webdriver
来自selenium.webdriver.chrome.options import选项
选项=选项()
选项。 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/')
使用 DesiredCapabilities Class:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
cap = DesiredCapabilit ies.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/')
$ c使用Chrome作为服务
$ b
:
来自selenium import webdriver
将selenium.webdriver.chrome.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')
让我知道这个答案你的问题。
I used Selenium with Python Chrome webdriver.In my code I used:
driver = webdriver.Chrome(executable_path = PATH_TO_WEBDRIVER)to point the webdriver to the webdriver executable. Is there a way to point webdriver to the Chrome Browser binaries?
In https://sites.google.com/a/chromium.org/chromedriver/capabilities they have the following (which I assume it what I'm looking for):
ChromeOptions options = new ChromeOptions(); options.setBinary("/path/to/other/chrome/binary");Anyone has an example for Python?
解决方案Here is the Answer to your Question:
You can set Chrome Browser Binary to chrome webdriver in Python through the following ways:
Using Options Class:
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/')Using DesiredCapabilities Class:
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/')Using Chrome as a Service:
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')Let me know if this Answers your Question.
这篇关于通过Python中的chromedriver设置chrome浏览器二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!