【问题标题】:Getting a NotADirectoryError when running selenium运行 selenium 时出现 NotADirectoryError
【发布时间】:2020-12-06 09:14:01
【问题描述】:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from bs4 import BeautifulSoup

my_username = "username"
my_password = "pass"

driver = webdriver.Firefox()
driver.get("http://www.twitch.tv/user/login")
elem_user = driver.find_element_by_id("login_user_login")
elem_passwd = driver.find_element_by_id("user[password]")
elem_user.send_keys(my_username)
elem_passwd.send_keys(my_password + Keys.RETURN)
time.sleep(5)

html = driver.page_source
soup = BeautifulSoup(html)
logginTag = soup.find("a", {"id" : "user_display_name"})
print(logginTag)
driver.close()

error- driver = webdriver.Firefox() 文件 “/Users/grey/.pyenv/versions/3.7.3/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py”, 第 164 行,在 init 中 self.service.start() 文件“/Users/grey/.pyenv/versions/3.7.3/lib/python3.7/site-packages/selenium/webdriver/common/service.py”,第 76 行,开始 stdin=PIPE) 文件“/Users/grey/.pyenv/versions/3.7.3/lib/python3.7/subprocess.py”,行 775,在 初始化 restore_signals,start_new_session)文件“/Users/grey/.pyenv/versions/3.7.3/lib/python3.7/subprocess.py”,行 第1522章 raise child_exception_type(errno_num, err_msg, err_filename) NotADirectoryError: [Errno 20] Not a directory: 'geckodriver'

【问题讨论】:

    标签: python selenium selenium-webdriver beautifulsoup


    【解决方案1】:

    当您使用浏览器时,您需要驱动程序实例进行交互,例如,如果您想使用 chrome 驱动程序,则需要 chrome 驱动程序 exe,如果您想打开 firefox,则需要 gecko 驱动程序

    https://github.com/mozilla/geckodriver/releases你可以从这个链接和安装路径下载最新的驱动程序并重新运行项目

    【讨论】:

    • 感谢您的回答,但我已经下载了 geckodrive 可执行文件并且我也使用了 - driver = webdriver.Firefox(executable_path='/Users/grey/Downloads/geckodriver')
    • 现在我收到此错误throwbin.io/FRmNFqo
    • 您是否更改了 firefox 设置?
    • 喜欢吗?如果这改变了任何东西,我也正在使用 mac
    • 我没有安装 firefox 浏览器
    【解决方案2】:

    基于

    NotADirectoryError: [Errno 20] Not a directory: 'geckodriver'
    

    建议:

    • 确保您已成功安装 Fixefox,通过在控制台中启动 firefox 来验证它
    • 从https://github.com/mozilla/geckodriver/releases下载 geckodriver 二进制文件,注意 geckodriver 必须与 Firefox 版本匹配
    • 设置路径。演示driver = webdriver.Firefox(executable_path=r'/User/xxx/geckodriver')

    【讨论】:

    • 这对我不起作用我现在收到此错误throwbin.io/FRmNFqo
    • @Juzec 根据你给的selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities,我想问一个问题,你的电脑上安装了firefox吗?
    猜你喜欢
    • 1970-01-01
    • 2012-02-15
    • 1970-01-01
    • 2011-01-25
    • 2019-11-27
    • 2015-02-17
    • 1970-01-01
    • 1970-01-01
    • 2012-07-30
    相关资源
    最近更新 更多