【发布时间】:2019-08-17 22:21:15
【问题描述】:
我已经尝试了许多 stackoverflow 上给出的解决方案,但都没有奏效。
我想在 Windows 上使用 ubuntu shell 使用 python 在 selenium 中打开 google chrome,但是每当我这样做时都会出错。 Terminal where I run the code as well as the folder path
我试图通过在 webdriver.Chrome 函数中指定路径来做到这一点,
webdriver.Chrome('/path/to/chromedriver.exe')
但同样的错误不断发生,
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/vinve/Desktop/chromedriver_win32/chromedriver.exe'
在处理上述异常的过程中,又发生了一个异常:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
我尝试使用双斜杠和原始字符串输入路径,但没有任何效果。
我还将 chromedriver.exe 文件添加到脚本文件夹中,但这没有帮助。我还像 webdriver.Chrome(/path/to/chromedriver) 那样运行了没有 .exe 的路径,但这不起作用。我还尝试在 --headless 模式下使用 chrome_options 运行它,但这没有用。 (所有这些选项都给出了上面相同的错误)
编辑: 回答: 我想到了!事实上,虽然我使用的是 Windows 10,但我使用的是 Windows Subsystem for Linux(Ubuntu shell)。所以在 webdriver.Chrome(/path/to/chromedriver.exe) 中指定的路径不应该以 C:/path/to/driver.exe 开头,而应该是 /mnt/c/Users/path/to/ chromedriver.exe
【问题讨论】:
-
确保带有
.exe的chrome 驱动程序不在您的位置。如果没有.exe尝试:webdriver.Chrome('/path/to/chromedriver') -
您好,我在没有 .exe 的情况下执行了此操作,但再次出现关于没有此类文件或目录的相同错误(在文件夹中没有用于 chromedriver 的 .exe,因此我在没有 .exe 的情况下实现了它) .你有什么想法为什么?我很确定路径是正确的(显示在原始帖子的图片中)。
标签: python selenium web-scraping