webdriver.Chrome()报错,FileNotFoundError: [Errno 2] No such file or directory: 'nul'
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了webdriver.Chrome()报错,FileNotFoundError: [Errno 2] No such file or directory: 'nul'相关的知识,希望对你有一定的参考价值。
>>> from selenium import webdriver>>> webdriver.Chrome()Traceback (most recent call last): File "D:\Program Files\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start stdin=PIPE) File "D:\Program Files\Python36\lib\subprocess.py", line 667, in __init__ errread, errwrite) = self._get_handles(stdin, stdout, stderr) File "D:\Program Files\Python36\lib\subprocess.py", line 917, in _get_handles c2pwrite = msvcrt.get_osfhandle(self._get_devnull()) File "D:\Program Files\Python36\lib\subprocess.py", line 775, in _get_devnull self._devnull = os.open(os.devnull, os.O_RDWR)FileNotFoundError: [Errno 2] No such file or directory: 'nul'During handling of the above exception, another exception occurred:Traceback (most recent call last): File "<pyshell#5>", line 1, in <module> webdriver.Chrome() File "D:\Program Files\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 68, in __init__ self.service.start() File "D:\Program Files\Python36\lib\site-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' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
参考技术A python脚本中selenium启动浏览器报错os.path.basename(self.path), self.start_error_message) selenium.common.excephttps://www.cnblogs.com/z3286586/p/11096117.html
在python脚本中,使用selenium启动浏览器报错,原因是未安装浏览器驱动,报错内容如下:
# -*- coding:utf-8 -*-
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.baidu.com")
报错提示如下所示:
Traceback (most recent call last):
File "D:\Program Files\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "D:\Program Files\Python36\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "D:\Program Files\Python36\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/Program Files/Python36/baidu.py", line 4, in <module>
driver = webdriver.Firefox()
File "D:\Program Files\Python36\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
self.service.start()
File "D:\Program Files\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
解决方案:安装Chrome浏览器驱动
1.下载 chromedriver_win32.zip,根据浏览器版本下载对应的压缩包;
下载地址:https://sites.google.com/a/chromium.org/chromedriver/downloads
2.解压后将chromedriver.exe文件放到系统环境变量Path路径下,例如:已将D:\Program Files\Python36\ 添加到系统环境变量Path路径下,将chromedriver.exe文件放到D:\Program Files\Python36\ 目录下即可;(20200319,把chromedriver.exe放到scripts提示错误)
以上是关于webdriver.Chrome()报错,FileNotFoundError: [Errno 2] No such file or directory: 'nul'的主要内容,如果未能解决你的问题,请参考以下文章
关于python+selenium+Chrome的一些问题。get报错。请求大佬帮助
selenium - webdriver - 截图方法get_screenshot_as_file()
chrome窗口报错 出现 "您使用的是不受支持的命令行标记:--ignore-certificate-errors
使用python通过selenium模拟打开chrome窗口报错 出现 "您使用的是不受支持的命令行标记:--ignore-certificate-errors