你好,想請問day019的sample為何會出現Message: 'chromedriver' executable needs to be in PATH這樣的錯誤訊息?
import requests
from bs4 import BeautifulSoup
r = requests.get("https://hahow.in/courses")
d = BeautifulSoup(r.text, 'html.parser')
d.body.text
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from bs4 import BeautifulSoup
browser = webdriver.Chrome(executable_path='chromedriver')
browser.get("https://hahow.in/courses")
-------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
/srv/conda/envs/notebook/lib/python3.7/site-packages/selenium/webdriver/common/service.py in start(self)
75 stderr=self.log_file,
---> 76 stdin=PIPE)
77 except TypeError:
/srv/conda/envs/notebook/lib/python3.7/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)
799 errread, errwrite,
--> 800 restore_signals, start_new_session)
801 except:
/srv/conda/envs/notebook/lib/python3.7/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, restore_signals, start_new_session)
1550 err_msg += ': ' + repr(err_filename)
-> 1551 raise child_exception_type(errno_num, err_msg, err_filename)
1552 raise child_exception_type(err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver': 'chromedriver'
During handling of the above exception, another exception occurred:
WebDriverException Traceback (most recent call last)
<ipython-input-5-a1aece70cfe3> in <module>
----> 1 browser = webdriver.Chrome(executable_path='chromedriver')
2 browser.get("https://hahow.in/courses")
/srv/conda/envs/notebook/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py in __init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, keep_alive)
71 service_args=service_args,
72 log_path=service_log_path)
---> 73 self.service.start()
74
75 try:
/srv/conda/envs/notebook/lib/python3.7/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: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
回答列表
-
2020/07/03 上午 11:25Jia贊同數:1不贊同數:0留言數:1
這個錯誤是指程式在你指定的路徑找不到chromedriver。
Selenium 需要透過 chromeDriver驅動 來控制 Chrome 瀏覽器,
因此你要先去下載 chromeDriver驅動 (http://chromedriver.chromium.org/downloads),
看你電腦內 Chrome 是哪一個版本,就選擇對應的檔案下載,
將它解壓縮後出來的 chromedriver.exe 放到與你程式同樣的資料夾內即可。
-
2020/07/05 下午 07:02張維元 (WeiYuan)贊同數:1不贊同數:0留言數:0
嗨,補充一下,投影片當中有提到的事前準備在這裡: