Python Selenium 错误 : "WebDriverException: ' login' executable needs to be in PATH.“

标签 python selenium web-scraping selenium-chromedriver

我需要使用 Selenium 从网站上抓取数据,并且在 pip 安装 selenium 并将 chrome 驱动程序添加到我的路径中后,出现错误。这是我的代码:

from selenium import webdriver

driver = webdriver.Chrome('https://secure.consumerreports.org/ec/login')

username = driver.find_element_by_id("signin-username")
password = driver.find_element_by_id("signin-password")

username.send_keys("myname@university.edu")
password.send_keys("pa$$w0rd")

driver.find_element_by_id('signin-btn').click()

print('Login complete.')

我得到:

WebDriverException: 'login' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

为了确定,我通过终端 pip 安装了 selenium,这是成功的,我下载了 mac 的 chrome 驱动程序 ( https://sites.google.com/a/chromium.org/chromedriver/downloads ),解压缩它,并将驱动程序本身粘贴到我的 PATH 中。我在终端中输入 echo $PATH ,它打印: /Users/[我的名字]/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin。我不被允许将驱动程序粘贴到 /usr/bin/bin/usr/sbin/sbin,但其他路径都很好。

根据错误消息,似乎我必须下载某种“登录”驱动程序才能登录。我一直未能成功找到这样的驱动程序。

我是 Selenium 新手,我不知道下一步该做什么。任何指导将不胜感激。

最佳答案

您提供给 webdriver.Chrome() 的路径应该是可执行文件的路径,如果您已经在 PATHS 中提供了正确的文件夹,则什么都不是。

然后你使用方法get来访问你想要抓取的url

driver = webdriver.Chrome(executable_path="path/to/chromedriver")
driver.get('https://secure.consumerreports.org/ec/login')

关于Python Selenium 错误 : "WebDriverException: ' login' executable needs to be in PATH.“,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50894170/

相关文章:

python - 动态重载运算符

python - 使用滚动窗口准确检测数据帧中具有重复值(相同头部和相同尾部)的序列

python - 使用python查找大文件中最后一次出现的单词

python - 找到 html 元素 bs4 子元素的最快方法

Python MySQLdb查询参数 "IS NULL"而不是 "= NULL"

python - 使用 PhantomJs 拒绝连接

找到java selenium元素但单击不起作用

java - Selenium 网格: Use custom browser location with RemoteWebDriver

Python:Beautifulsoup 返回 None 或 [ ]

html - XPath - 选择所有文本作为单行