python - Selenium 打开 geckdriver 错误:NotADirectoryError: [WinError 267] 目录名无效
问题描述
import time
import pyautogui
import sys
from selenium import webdriver
tabTimer = 0
fileRun = __file__
fileRun = fileRun.replace("app.py", "geckodriver.exe")
print(fileRun)
stall = input("enter filepath: ")
driver = webdriver.Firefox(fileRun)
driver.get("htpps://google.com")
每当我尝试打开 geckodriver 时,无论是使用下面使用的方法还是手动将文件路径输入为 r"",它都无法正常工作并生成以下错误。任何帮助或建议表示赞赏,谢谢!
c:\Users\ellio\Desktop\main\app.py:22: DeprecationWarning: firefox_profile has been deprecated, please pass in an Options object
driver = webdriver.Firefox(fileRun)
Traceback (most recent call last):
File "c:\Users\ellio\Desktop\main\app.py", line 22, in <module>
driver = webdriver.Firefox(fileRun)
File "C:\Users\ellio\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 160, in __init__
firefox_profile = FirefoxProfile(firefox_profile)
File "C:\Users\ellio\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\firefox\firefox_profile.py", line 74, in __init__
shutil.copytree(self.profile_dir, newprof,
File "C:\Users\ellio\AppData\Local\Programs\Python\Python39\lib\shutil.py", line 555, in copytree
with os.scandir(src) as itr:
NotADirectoryError: [WinError 267] The directory name is invalid: 'c:\\Users\\ellio\\Desktop\\main\\geckodriver.exe'
解决方案
NotADirectoryError: [WinError 267]
表示webriver的火狐方式是在找目录,而不是文件路径。如果您查看堆栈跟踪,您会看到错误是由os.scandir
. os.scandir
只接受目录,不接受直接文件路径。
如果你geckodriver.exe
在路径的尽头省略它应该没问题。
推荐阅读
- wordpress - get_the_post_thumbnail_url fullsize d它不起作用
- django - Django 密码重置超时
- python - 基于大小不同的 3 列合并数据集
- database - 不能在 Room 中添加第二个视图参数?
- android - Pupil detection project with OpenCV & Android-Studio gets ArrayIndexOutOfBoundsException
- flutter - 多个用户的多个共享偏好,有必要吗?
- javascript - 在 jsp 文件中获取网页中与脚本相关的 HTML 标记(基本 XSS)(CWE ID 80)
- angularjs - 以角度动态添加高图中的平均线
- .net - 如何使用 EMGUCV 缩减函数(C# 或 VB)获取图像的像素总和(投影)
- azure - 存储在 aws 机密管理器中的 Azure 机密