[英]Jupyter Notebook selenium webdriver webdriver doesn't work/open
我安装了te selenium模块,进入coe打开webbrowser,但是报错,webbrowser打不开。 实际上访问我的浏览器不起作用。 我是 Python 新手,正在学习在线课程。 前两行是我的输入,下面是错误。 有人可以帮忙吗?
from selenium import webdriver
browser=webdriver.Firefox()
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
C:\Users\Public\Anaconda\lib\site-packages\selenium\webdriver\common\service.py in start(self)
75 stderr=self.log_file,
---> 76 stdin=PIPE)
77 except TypeError:
C:\Users\Public\Anaconda\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
774 errread, errwrite,
--> 775 restore_signals, start_new_session)
776 except:
C:\Users\Public\Anaconda\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
1177 os.fspath(cwd) if cwd is not None else None,
-> 1178 startupinfo)
1179 finally:
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
WebDriverException Traceback (most recent call last)
<ipython-input-91-0532aeb968a6> in <module>
----> 1 browser=webdriver.Firefox()
C:\Users\Public\Anaconda\lib\site-packages\selenium\webdriver\firefox\webdriver.py in __init__(self, firefox_profile, firefox_binary, timeout, capabilities, proxy, executable_path, options, service_log_path, firefox_options, service_args, desired_capabilities, log_path, keep_alive)
162 service_args=service_args,
163 log_path=service_log_path)
--> 164 self.service.start()
165
166 capabilities.update(options.to_capabilities())
C:\Users\Public\Anaconda\lib\site-packages\selenium\webdriver\common\service.py in start(self)
81 raise WebDriverException(
82 "'%s' executable needs to be in PATH. %s" % (
---> 83 os.path.basename(self.path), self.start_error_message)
84 )
85 elif err.errno == errno.EACCES:
WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
将可执行路径设置为geckodriver.exe
例如,
from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'your\path\geckodriver.exe')
如果您获得错误的权限,请尝试从路径中删除 [r'],只需“excecutable_path='path\\to\\your'diretory'”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.