英文:
Message:Unable to obtain chromedriver using Selenium Manager
问题
我在我的Jupyter笔记本上尝试编写这段代码,但出现了错误。我的目标是进行网络爬虫。
driver = webdriver.Chrome(ChromeDriverManager().install())
我还使用pip安装了selenium和webdriver-manager。
英文:
I've tried writing this code on my jupyter notebook, and it shows me the error. My objective is to carry out web scrapping.
driver = webdriver.Chrome(ChromeDriverManager().install())
I've also installed selenium using pip and webdriver-manager using pip as well.
答案1
得分: 2
The output of ChromeDriverManager().install()
is an executable_path
to the driver, but executable_path
was removed in selenium
4.10.0
. That's why you're seeing the error after passing the value into webdriver.Chrome()
. Here are the changes: Link
Note that executable_path
was removed. If you want to pass in an executable_path
, you'll have to use the service
arg now. (service=Service(executable_path='./chromedriver')
) But Selenium Manager is now fully included with selenium
4.10.0
, so this is all you need:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
service = Service()
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=service, options=options)
# ...
driver.quit()
If the driver isn't found on your system PATH, Selenium Manager will automatically download it for you.
英文:
The output of ChromeDriverManager().install()
is an executable_path
to the driver, but executable_path
was removed in selenium
4.10.0
. That's why you're seeing the error after passing the value into webdriver.Chrome()
. Here are the changes:
https://github.com/SeleniumHQ/selenium/commit/9f5801c82fb3be3d5850707c46c3f8176e3ccd8e
Note that executable_path
was removed. If you want to pass in an executable_path
, you'll have to use the service
arg now. (service=Service(executable_path='./chromedriver')
) But Selenium Manager is now fully included with selenium
4.10.0
, so this is all you need:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
service = Service()
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(service=service, options=options)
# ...
driver.quit()
If the driver isn't found on your system PATH, Selenium Manager will automatically download it for you.
答案2
得分: 1
尝试删除 ChromeDriverManager
,如果您的 Selenium 版本为 v4.6.0
或更高,则不需要它。
将下面的代码更改为:
driver = webdriver.Chrome()
英文:
Can you try by removing the ChromeDriverManager
, you don't need it if your selenium version is v4.6.0
or above.
Change below:
driver = webdriver.Chrome(ChromeDriverManager().install())
To:
driver = webdriver.Chrome()
答案3
得分: 1
Selenium Manager
Selenium Manager 是一个新工具,可以帮助获取所需的浏览器驱动程序,以便在不需要其他配置的情况下运行 Selenium。Selenium Manager 的 Beta 1 版本会为 Chrome、Firefox 和 Edge 配置浏览器驱动程序,如果它们不在 PATH
中。因此,要使用 Selenium 4.6 及更高版本运行 Selenium 测试,只需安装 [tag:google-chrome]、[tag:firefox] 或 [tag:microsoft-edge] 即可。如果已经安装了浏览器驱动程序,此功能将被完全忽略。
Current Status
Selenium Manager 工具目前仍处于测试阶段,Selenium 正逐步增加对此功能的支持。当前的实现是一个 fall-back
选项,这意味着只有在否则会执行失败的情况下才会使用它。只要您在适当的 Service
类中指定了驱动程序的位置(或者在 Java 中使用 System Properties),Selenium Manager 将不会被使用。
Solution
有两种不同的方法如下:
-
您完全可以避免使用 webdriver-manager,您的有效代码块将是:
driver = webdriver.Chrome()
-
要继续使用 webdriver-manager,您必须使用 Service 类,您的有效代码块将是:
driver = webdriver.Chrome(service=ChromeDriverManager().install())
英文:
Selenium Manager
Selenium Manager is the new tool that helps to get the required browser drivers to run Selenium out of the box. Beta 1 of Selenium Manager configures the browser drivers for Chrome, Firefox, and Edge if they are not present on the PATH
. So To run a Selenium test with Selenium 4.6 and onwards you just need to have [tag:google-chrome], [tag:firefox] or [tag:microsoft-edge] installed. If you already have browser drivers installed, this feature will be ignored completely.
Current Status
Selenium Manager tool is still in beta phase and Selenium is gradually adding support for this feature. The current implementation is a fall-back
option, which means it should only get used if the code execution would otherwise fail. So long as you specify the location of the driver in the appropriate Service
class (or using System Properties in Java), the Selenium Manager will not be used.
Solution
There are 2 different approaches as follows:
-
You can totally avoid webdriver-manager and your effective code block will be:
driver = webdriver.Chrome()
-
To keep using the webdriver-manager you have to use the Service class and your effective code block will be:
driver = webdriver.Chrome(service=ChromeDriverManager().install())
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论