gpt4 book ai didi

python - 如何在 ubuntu 16.04 上为 python3 selenium 安装 firefoxdriver webdriver?

转载 作者:行者123 更新时间:2023-12-04 13:42:28 25 4
gpt4 key购买 nike

我在 Ubuntu 16.04 上安装了 python3-selenium apt 包。安装时,收到一条消息:

Suggested packages:
chromedriver firefoxdriver
The following NEW packages will be installed:
python3-selenium

当我尝试运行以下 python 代码时,

#! /usr/bin/python3.5
from selenium import webdriver
import time

def get_profile():
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.privatebrowsing.autostart", True)
return profile

def main():
browser = webdriver.Firefox(firefox_profile=getProfile())

#browser shall call the URL
browser.get("http://www.google.com")
time.sleep(5)
browser.quit()

if __name__ == "__main__":
main()

我收到以下错误:

Traceback (most recent call last): File "./test.py", line 19, in main() File "./test.py", line 11, in main browser = webdriver.Firefox(firefox_profile=getProfile()) File "/usr/lib/python3/dist-packages/selenium/webdriver/firefox /webdriver.py", line 77, in init self.binary, timeout), File "/usr/lib/python3/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in init self.profile.add_extension() File "/usr/lib/python3/dist-packages/selenium/webdriver/firefox/firefox_profile.py", line 91, in add_extension self._install_extension(extension) File "/usr/lib/python3/dist-packages/selenium/webdriver/firefox/firefox_profile.py", line 251, in _install_extension compressed_file = zipfile.ZipFile(addon, 'r') File "/usr/lib/python3.5/zipfile.py", line 1009, in init self.fp = io.open(file, filemode) FileNotFoundError: [Errno 2] No such file or directory: '/usr/lib /firefoxdriver/webdriver.xpi'

我确实在 Ubuntu 存储库中搜索了名为 firefoxdriver 的软件包,但不存在。我该如何解决这个问题?

感谢任何有关安装网络驱动程序的帮助!

最佳答案

您缺少的包名为 firefox-geckodriver。您可以通过 sudo apt-get install firefox-geckodriver 或从 https://github.com/mozilla/geckodriver/releases 下载,将其放入您的 $PATH(例如 /usr/bin)并使其可执行。

关于python - 如何在 ubuntu 16.04 上为 python3 selenium 安装 firefoxdriver webdriver?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39179320/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com