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/')
上面是我的代码,但是当我尝试运行它时,我收到 chrome_options 错误。有人可以帮我解决这个问题吗?
webdriver.Chrome 构造函数不再具有 'chrome_options' 参数。 它已被弃用,现在您必须使用“options”参数。
这是 Chrome 类:
class WebDriver(ChromiumDriver):
"""Controls the ChromeDriver and allows you to drive the browser."""
def __init__(
self,
options: Options = None,
service: Service = None,
keep_alive: bool = True,
) -> None:
"""Creates a new instance of the chrome driver. Starts the service and
then creates new instance of chrome driver.
:Args:
- options - this takes an instance of ChromeOptions
- service - Service object for handling the browser driver if you need to pass extra details
- keep_alive - Whether to configure ChromeRemoteConnection to use HTTP keep-alive.
"""
self.service = service if service else Service()
self.options = options if options else Options()
self.keep_alive = keep_alive
self.service.path = DriverFinder.get_path(self.service, self.options)
super().__init__(
DesiredCapabilities.CHROME["browserName"],
"goog",
self.options,
self.service,
self.keep_alive,
)