我开始自动化的无聊的东西书,我试图打开一个铬网络浏览器通过python。我已经安装了selenium和
我试着运行这个文件:
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')但由于这个原因,我得到了一个错误:
Traceback (most recent call last): File "C:\Program Files
(x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.py",
line 74, in start
stdout=self.log_file, stderr=self.log_file) File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session) File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 990, in _execute_child
startupinfo) FileNotFoundError: [WinError 2] The system cannot find the file specified在处理上述异常的过程中,发生了另一个异常:
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-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py",
line 62, in __init__
self.service.start() File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.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发布于 2017-02-27 06:11:54
您需要指定色度驱动程序位于的路径。
chromedriver.exe (对于非Windows用户,它只是称为chromedriver):
browser = webdriver.Chrome(executable_path=r"C:\path\to\chromedriver.exe")
(将executable_path设置为色度驱动器所在的位置。)
如果您已将chromedriver放置在系统路径上,则只需执行以下操作即可快捷:
browser = webdriver.Chrome()chmod +x chromedriver发布于 2019-09-12 18:42:36
这里有一个更简单的解决方案:安装包,在脚本中导入它,它就完成了。
一步
from selenium import webdriver
import chromedriver_binary # Adds chromedriver binary to path
driver = webdriver.Chrome()
driver.get("http://www.python.org")https://stackoverflow.com/questions/42478591
复制相似问题