Python浏览器驱动程序
我开始读《自动化无聊的东西》这本书,并试图通过python打开chrome web浏览器。我已经安装了selenium和 我已尝试运行此文件:Python浏览器驱动程序,python,selenium,selenium-chromedriver,Python,Selenium,Selenium Chromedriver,我开始读《自动化无聊的东西》这本书,并试图通过python打开chrome web浏览器。我已经安装了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://auto
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/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
Traceback(最近一次调用last):文件“C:/Program文件
(x86)/Python36-32/test.py“,第5行,in
browser=webdriver.Chrome()文件“C:\ProgramFiles(x86)\Python36-32\lib\site packages\selenium\webdriver\Chrome\webdriver.py”,
第62行,in_uuuinit__
self.service.start()文件“C:\Program Files(x86)\Python36-32\lib\site packages\selenium\webdriver\common\service.py”,
第81行,开始
os.path.basename(self.path)、self.start\u error\u message)selenium.common.exceptions.WebDriverException:message:'chromedriver'
可执行文件需要在路径中。请看
https://sites.google.com/a/chromium.org/chromedriver/home
您需要指定chromedriver所在的路径
chromedriver.exe
(对于非Windows用户,它仅称为chromedriver
):
(将可执行路径设置为chromedriver所在的位置。)
如果已将chromedriver放置在系统路径上,则只需执行以下操作即可实现快捷方式:
browser=webdriver.Chrome()
chmod+x chromedriver
这里有一个更简单的解决方案:安装python chromedrive包,在脚本中导入它,就完成了 一步一步地:
1.pip安装chromedriver二进制文件
2.导入包
from selenium import webdriver
import chromedriver_binary # Adds chromedriver binary to path
driver = webdriver.Chrome()
driver.get("http://www.python.org")
参考资料:回溯已经告诉您,问题是:您的python代码无法执行
chromedriver
,因为在PATH中找不到它。将chromedriver
的位置添加到路径或将chromedriver
移动到路径中已存在的位置。这是否回答了您的问题?或者只需执行错误消息所述的操作,并将可执行文件放在系统路径中的某个位置即可执行pip安装chromedriver-binary@Prometheus是的,我在步骤1中提到,这对我不起作用,因为pip install chromedriver_binary安装的是最新版本(84),但我的chrome版本是83。所以我必须运行pip安装chromedriver二进制文件==83.0.4103.39。你可以在这里找到其他版本:它非常简单,不起作用
browser = webdriver.Chrome(executable_path=r"C:\path\to\chromedriver.exe")
from selenium import webdriver
import chromedriver_binary # Adds chromedriver binary to path
driver = webdriver.Chrome()
driver.get("http://www.python.org")