简体   繁体   中英

Jupyter Notebook selenium webdriver webdriver doesn't work/open

I installed te selenium module and entered the coe to open the webbrowser, but I get an error and the webbrowser doesn't open. Actually to access my browser doesn't work. I am new in Python an I am following an online course. The first 2 lines are my entry and below is the error. Could someon please help?

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.

Set your executable path to geckodriver.exe

For example,

from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'your\path\geckodriver.exe')

If you get wrong permission try to remove [r'] from the path just "excecutable_path='path\\to\\your'diretory'"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM