显然,这可能是由于您的Firefox和Selenium之间的不兼容所致。请尝试
pip install --upgradeselenium,如果错误仍然存在,请尝试下载其他版本的Firefox或gecko驱动程序。
关于消息:
'geckodriver' executable needs to be in PATH
您可以在脚本上设置驱动程序的路径:
ff_profile_dir = "/usr/local/selenium/webdriver/firefox"ff_profile = selenium.webdriver.FirefoxProfile(profile_directory=ff_profile_dir)driver = selenium.webdriver.Firefox(ff_profile)
或者,根据此答案,您可以在Unix系统上的bash兼容shell上运行:
export PATH=$PATH:/path/to/directory/of/executable/downloaded/in/previous/step
在Windows上,您将需要更新Path系统变量以手动或命令行将完整目录路径添加到可执行geckodriver(不要忘记在将可执行geckodriver添加到系统PATH中生效后重新启动系统)。其原理与Unix相同。



