问题:
selenium +pythpon+chromedriver+chrome 报错,提示IOError: [Errno 2] No such file or directory: ‘nul’
详细信息:
系统:win10 64位
Chrome版本 65.0.3325.146(正式版本) (64 位)
ChromeDriver 2.35.528161
python 版本-2.7.13.amd64
python代码
# -*- coding: UTF-8 -*-
import os
from selenium import webdriver
# service_log_path = 'chromedriver.log'
# service_args = ['--verbose', '--no-sandbox']
# driver = webdriver.Chrome( service_args=service_args,service_log_path=service_log_path)
driver = webdriver.Chrome()
driver.get('http://mail.sina.net')
print(driver.title)
错误提示:
Traceback (most recent call last):
File "H:/scrip/python/test/11.py", line 7, in <module>
driver = webdriver.Chrome()
File "C:\Python27\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 67, in __init__
log_path=service_log_path)
File "C:\Python27\lib\site-packages\selenium\webdriver\chrome\service.py", line 42, in __init__
start_error_message="Please see https://sites.google.com/a/chromium.org/chromedriver/home")
File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 46, in __init__
log_file = open(os.devnull, 'wb')
IOError: [Errno 2] No such file or directory: 'nul'
定位问题
1.找到错误提示中代码
File “C:\Python27\lib\site-packages\selenium\webdriver\common\service.py”, line 46, in init
log_file = open(os.devnull, ‘wb’)
代码片段
if not _HAS_NATIVE_DEVNULL and log_file == DEVNULL:
log_file = open(os.devnull, 'wb')
定位到问题是open(‘nul’,’wb’)在我的电脑上不支持,
但是open(‘null’,’wb’)就可以运行成功
具体原因还在寻找答案
我估计是我电脑版本的问题
解决办法:
办法1:替换
log_file = open(os.devnull, ‘wb’)
为
log_file = open(‘null’, ‘wb’)
办法2:重装系统
我不会告诉你我都试过了,所以才有这两种办法。
重点来了,以后要装纯净版系统