問題描述
我正在開始自動化這本無聊的東西,我正在嘗試通過 python 打開一個 chrome 網絡瀏覽器.我已經安裝了 selenium 和
I'm beginning the automate the boring stuff book and I'm trying to open a chrome web browser through python. I have already installed selenium and
我已嘗試運行此文件:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
browser = webdriver.Chrome()
browser.get('https://automatetheboringstuff.com')
但正因為如此,我得到了這個錯誤:
But because of that I get this Error:
Traceback (most recent call last): File "C:Program Files
(x86)Python36-32libsite-packagesseleniumwebdrivercommonservice.py",
line 74, in start
stdout=self.log_file, stderr=self.log_file) File "C:Program Files (x86)Python36-32libsubprocess.py", line 707, in __init__
restore_signals, start_new_session) File "C:Program Files (x86)Python36-32libsubprocess.py", line 990, in _execute_child
startupinfo) FileNotFoundError: [WinError 2] The system cannot find the file specified
在處理上述異常的過程中,又發生了一個異常:
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:/Program Files
(x86)/Python36-32/test.py", line 5, in <module>
browser = webdriver.Chrome() File "C:Program Files (x86)Python36-32libsite-packagesseleniumwebdriverchromewebdriver.py",
line 62, in __init__
self.service.start() File "C:Program Files (x86)Python36-32libsite-packagesseleniumwebdrivercommonservice.py",
line 81, 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
推薦答案
你需要指定你的chromedriver所在的路徑.
從此處下載所需平臺的 chromedriver.
將 chromedriver 放在系統路徑或代碼所在的位置.
Place chromedriver on your system path, or where your code is.
如果不使用系統路徑,請鏈接您的 chromedriver.exe
(對于非 Windows 用戶,它只是稱為 chromedriver
):
If not using a system path, link your chromedriver.exe
(For non-Windows users, it's just called chromedriver
):
browser = webdriver.Chrome(executable_path=r"C:path ochromedriver.exe")
(將 executable_path
設置為您的 chromedriver 所在的位置.)
(Set executable_path
to the location where your chromedriver is located.)
如果您已將 chromedriver 放置在系統路徑中,則只需執行以下操作即可快捷方式:
If you've placed chromedriver on your System Path, you can shortcut by just doing the following:
browser = webdriver.Chrome()
如果您運行的是基于 Unix 的操作系統,您可能需要在下載后更新 chromedriver 的權限以使其可執行:
If you're running on a Unix-based operating system, you may need to update the permissions of chromedriver after downloading it in order to make it executable:
chmod +x chromedriver
就是這樣.如果您仍然遇到問題,可以在其他 StackOverflow 文章中找到更多信息:可以'不要為 Selenium 使用 chrome 驅動程序
That's all. If you're still experiencing issues, more info can be found on this other StackOverflow article: Can't use chrome driver for Selenium
這篇關于Python Selenium Chrome 網絡驅動程序的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!