【问题标题】:webdriver.xpi not found - Python3, Linux Mint未找到 webdriver.xpi - Python3,Linux Mint
【发布时间】:2018-01-28 16:42:39
【问题描述】:

我是论坛的新手,但已搜索帖子以解决我的问题。

以下是我用来尝试进行故障排除的帖子: #1 #2 ~ 以及其他 Google 搜索结果。

我从 Windows 切换到 Linux Mint,但无法设置。总的来说,我对 Python/编程也很陌生,所以请耐心等待。

Linux Mint 安装了 Python2,但我已经用 Python3 完成了所有练习,所以我安装了 Python 3,这意味着我还必须安装 Python3 版本的 Selenium、Geckodriver 等才能运行我的练习脚本用于网页抓取。

当我运行我的代码时,它会按预期提示输入搜索词,但随后会引发以下错误:

Traceback (most recent call last):
  File "/home/myName/Documents/Programming Misc/Python/craigslistSearch_linkGeneration_v02.py", line 15, in <module>
    browser = webdriver.Firefox()
  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'

这是有问题的代码:

from selenium import webdriver  #To launch the browser (Firefox)
from selenium.webdriver.common.keys import Keys #To be able to send special keys (i.e., DOWN, UP, RIGHT, LEFT, TAB, HOME, etc.)
import time #To pause the program for x seconds
import string #To run string.replace()
import requests

#prompt the user to enter their desired search term
print('Please enter your search term')
searchTerm = input()
newSearchTerm = str.replace(searchTerm, ' ', '+')



#open browser and navigate to craigslist + user-defined search term(s)
browser = webdriver.Firefox()
type(browser)
searchURL = browser.get('https://seattle.craigslist.org/search/sss?query=' + newSearchTerm)

【问题讨论】:

    标签: linux python-3.x selenium webdriver


    【解决方案1】:

    我怀疑您为 Python 3 安装了旧的 Selenium,因为 webdriver.xpi 是用于 Firefox 浏览器的旧版 Web 驱动程序,它已被 geckodriver 取代。

    请显示您安装的 Selenium、geckodriver 和其他相关内容的版本。

    如果你使用Selenium 2,它会尝试找到webdriver.xpi,因为Selenium 3,它会尝试找到geckodriver,所以尝试安装Selenium 3或更高版本。

    【讨论】:

    • 对不起,我按了 Enter 但没有完成输入 这里是 GeckoDriver ~ $ geckodriver --version geckodriver 0.11.1 我不知道为什么我找不到这些东西。我知道当我使用 Python2 时 Selenium 正在工作 me@me-Linux ~ $ ActivePython --version ActivePython: command not found me@me-Linux ~ $ activepython --version activepython: command not found me@me- Linux ~ $ activepython -version activepython: 找不到命令 me@me-Linux ~ $ requests -version requests: 找不到命令 me@me-Linux ~ $ selenium --version selenium: 找不到命令
    • 你安装了哪个版本的 Selenium for python?
    • 我很抱歉 - 今天下班后我会尝试重新格式化我的回复,以便更容易阅读。为了回答你的问题,我不确定我有什么版本的硒。我知道我有一些版本,因为它可以在 Python 2.x 上运行——值得我卸载 Python2 及其依赖项吗?这会简化事情并减少问题吗?
    • 已解决:我下载了 Selenium 的“Python Wheel”版本,它似乎有效。我最初下载了 Source tar 包。这是我去的地方:(pypi.python.org/pypi/selenium#downloads)
    猜你喜欢
    • 2015-02-28
    • 2016-03-20
    • 1970-01-01
    • 2012-08-10
    • 2022-08-08
    • 1970-01-01
    • 2020-05-25
    • 1970-01-01
    • 2013-12-21
    相关资源
    最近更新 更多