python - Python Selenium Chrome Webdriver 未安装
问题描述
我正在尝试自动安装最新版本的 Chrome 驱动程序,然后将其用于我的脚本,但遇到了错误。关于这里有什么问题的任何想法?我的缓存有什么东西吗?
driver2 = webdriver.Chrome(ChromeDriverManager().install())
options = selenium.webdriver.ChromeOptions()
#options.add_argument('headless')
options.add_argument('window-size=1920x1080')
driver = webdriver.Chrome(driver2, options=options)
错误:
[WDM] - Looking for [chromedriver 89.0.4389.23 win32] driver in cache
[WDM] - File found in cache by path [C:\Users\xxx\.wdm\drivers\chromedriver\89.0.4389.23\win32\chromedriver.exe]
Traceback (most recent call last):
File "C:\Users\xxx\Python\Price Tracking\Real Estate\RealEstate-Scraping.py", line 60, in <module>
driver = webdriver.Chrome(driver2, options=options)
File "C:\Python38\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Python38\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Python38\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Python38\lib\subprocess.py", line 1247, in _execute_child
args = list2cmdline(args)
File "C:\Python38\lib\subprocess.py", line 549, in list2cmdline
for arg in map(os.fsdecode, seq):
File "C:\Python38\lib\os.py", line 818, in fsdecode
filename = fspath(filename) # Does type-checking of `filename`.
TypeError: expected str, bytes or os.PathLike object, not WebDriver
解决方案
你需要告诉webdriver的路径:
webdriver.chrome(executable_path=*path*,options=options)
但
driver2 = webdriver.Chrome(ChromeDriverManager().install())
创建一个新的硒实例。
driver = webdriver.Chrome(ChromeDriverManager().install(),options=options)
应该适用于您的用例 - 您的代码的第一行不是必需的。
请注意,“无头”也需要在它前面加上“--”。
完整代码:
options = selenium.webdriver.ChromeOptions()
#options.add_argument('--headless')
#could also do options.headless = True
options.add_argument('--window-size=1920x1080')
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
driver.get('enterwebsite.ext')
#do other stuff
推荐阅读
- c# - 使用 LINQ 查询选择对象列表
- forms-authentication - 从用户那里获取身份验证 cookie 的方法
- python - 在 Python 中将 CSV 转换为 CLF
- php - 使用 POST 方法打开新窗口导致 404 错误(找不到文件)
- python - 尝试使用 sklearn 拟合 GaussianNB 分类器时出现 ValueError
- java - 循环链表:NullPointerException 错误
- c# - 为什么我的简单 C# 程序会立即退出?
- matlab - 在符号数组中的特定索引中为符号赋值
- java - 列表
表现为列表 - javascript - svg 中的函数不是通过 html 中的 javascript 调用的