Linux 上缺少 Selenium Firefox 配置文件
Selenium Firefox Profile Missing on Linux
我正在尝试让 Selenium 在 Ubuntu 虚拟机上运行。我有一个赫克的时间这样做。无论我做什么,我总是得到以下对话:
我不需要特别使用任何配置文件。我最初认为 Selenium\Gecko 为其实例创建了一个临时配置文件。以下是我尝试过的所有内容。此外,我还尝试 运行 作为 sudo,and\or 将配置文件的所有权设置为 nobody
以及将配置文件目录的权限设置为 777
。 None 其中成果丰硕。我看过其他关于此的 SO 帖子,none 其中为我提供了导致答案的任何内容,这显然是我来这里的原因。
# create a new Firefox session
# binary = FirefoxBinary('/snap/bin/firefox')
# binary = FirefoxBinary('/usr/local/bin/geckodriver')
profile = webdriver.FirefoxProfile(profile_directory='/home/jaberwocky/snap/firefox/common/.mozilla/firefox/tm4nraze.selenium')
# profile.set_preference("browser.download.folderList",2)
# profile.set_preference("browser.download.manager.showWhenStarting",False)
# profile.set_preference("browser.download.dir", os.getcwd())
# profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream")
driver = webdriver.Firefox(firefox_profile=profile)
driver.implicitly_wait(20)
driver.get(base_url)
python_button = driver.find_element_by_class_name('sh-hide')
python_button.click()
硒版本 3.141.0
Firefox 版本 65.0.2
Python 版本 3.7.2
Linux 发行版 Ubuntu Budgie 18.04.2 LTS
关于这个问题的信息确实不多。我在这里做错了什么?
更新:
我为每次执行 gecko 找到了一个日志文件。这是它显示的内容:
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
/snap/firefox/185/bin/desktop-launch: line 174: /home/addohm/snap/firefox/common/.config/user-dirs.dirs: No such file or directory
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
cp: cannot create regular file '/home/addohm/snap/firefox/common/.config/': Not a directory
/snap/firefox/185/bin/desktop-launch: line 177: /home/addohm/snap/firefox/common/.config/user-dirs.dirs.md5sum: No such file or directory
/snap/firefox/185/bin/desktop-launch: line 177: /home/addohm/snap/firefox/common/.config/user-dirs.locale.md5sum: No such file or directory
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
1551441977454 mozrunner::runner INFO Running command: "/snap/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile.kvmA0GU2ZdrC"
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
/snap/firefox/185/bin/desktop-launch: line 174: /home/addohm/snap/firefox/common/.config/user-dirs.dirs: No such file or directory
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
cp: cannot create regular file '/home/addohm/snap/firefox/common/.config/': Not a directory
/snap/firefox/185/bin/desktop-launch: line 177: /home/addohm/snap/firefox/common/.config/user-dirs.dirs.md5sum: No such file or directory
/snap/firefox/185/bin/desktop-launch: line 177: /home/addohm/snap/firefox/common/.config/user-dirs.locale.md5sum: No such file or directory
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
Gtk-Message: Failed to load module "canberra-gtk-module"
Gtk-Message: Failed to load module "canberra-gtk-module"
(firefox:27487): Gtk-WARNING **: Error loading theme icon 'dialog-warning' for stock: Icon 'dialog-warning' not present in theme Pocillo
没有~/snap/firefox/common/.config/
但是有~/snap/firefox/current/.config/
.
直接使用Firefox创建的配置文件好像会失败
您可以尝试制作一个复制文件夹并使用它。
关于直接选择配置文件失败的原因,您可以在这里查看详细信息:
这个问题似乎与使用 Snap 而不是 apt
安装 Firefox
直接相关。
参考:https://ubuntuforums.org/showthread.php?t=2398478
它一开始就工作,没有特定的配置文件。
不幸的是,如果您使用内置软件包管理器安装 Firefox,它将通过 snap 安装。所以请小心并安装:
sudo apt install firefox
Geckodriver 尝试从与 /home/username/snap/firefox...
不同的目录加载配置文件,因为它未配置为快照安装。如果您仍想使用 snap 安装,因为它提供了 apt 安装不提供的功能(就像我的情况),那么您仍然可以这样做:
from selenium.webdriver.firefox.options import Options
options = Options()
options.add_argument("-profile")
# put the root directory your default profile path here, you can check it by opening Firefox and then pasting 'about:profiles' into the url field
options.add_argument("/home/username/snap/firefox/common/.mozilla/firefox/dhklfoeb.default-18236362302398")
browser=webdriver.Firefox(options=options)
我正在尝试让 Selenium 在 Ubuntu 虚拟机上运行。我有一个赫克的时间这样做。无论我做什么,我总是得到以下对话:
我不需要特别使用任何配置文件。我最初认为 Selenium\Gecko 为其实例创建了一个临时配置文件。以下是我尝试过的所有内容。此外,我还尝试 运行 作为 sudo,and\or 将配置文件的所有权设置为 nobody
以及将配置文件目录的权限设置为 777
。 None 其中成果丰硕。我看过其他关于此的 SO 帖子,none 其中为我提供了导致答案的任何内容,这显然是我来这里的原因。
# create a new Firefox session
# binary = FirefoxBinary('/snap/bin/firefox')
# binary = FirefoxBinary('/usr/local/bin/geckodriver')
profile = webdriver.FirefoxProfile(profile_directory='/home/jaberwocky/snap/firefox/common/.mozilla/firefox/tm4nraze.selenium')
# profile.set_preference("browser.download.folderList",2)
# profile.set_preference("browser.download.manager.showWhenStarting",False)
# profile.set_preference("browser.download.dir", os.getcwd())
# profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream")
driver = webdriver.Firefox(firefox_profile=profile)
driver.implicitly_wait(20)
driver.get(base_url)
python_button = driver.find_element_by_class_name('sh-hide')
python_button.click()
硒版本 3.141.0
Firefox 版本 65.0.2
Python 版本 3.7.2
Linux 发行版 Ubuntu Budgie 18.04.2 LTS
关于这个问题的信息确实不多。我在这里做错了什么?
更新: 我为每次执行 gecko 找到了一个日志文件。这是它显示的内容:
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
/snap/firefox/185/bin/desktop-launch: line 174: /home/addohm/snap/firefox/common/.config/user-dirs.dirs: No such file or directory
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
cp: cannot create regular file '/home/addohm/snap/firefox/common/.config/': Not a directory
/snap/firefox/185/bin/desktop-launch: line 177: /home/addohm/snap/firefox/common/.config/user-dirs.dirs.md5sum: No such file or directory
/snap/firefox/185/bin/desktop-launch: line 177: /home/addohm/snap/firefox/common/.config/user-dirs.locale.md5sum: No such file or directory
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
1551441977454 mozrunner::runner INFO Running command: "/snap/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile.kvmA0GU2ZdrC"
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
/snap/firefox/185/bin/desktop-launch: line 174: /home/addohm/snap/firefox/common/.config/user-dirs.dirs: No such file or directory
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
cp: cannot create regular file '/home/addohm/snap/firefox/common/.config/': Not a directory
/snap/firefox/185/bin/desktop-launch: line 177: /home/addohm/snap/firefox/common/.config/user-dirs.dirs.md5sum: No such file or directory
/snap/firefox/185/bin/desktop-launch: line 177: /home/addohm/snap/firefox/common/.config/user-dirs.locale.md5sum: No such file or directory
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
Gtk-Message: Failed to load module "canberra-gtk-module"
Gtk-Message: Failed to load module "canberra-gtk-module"
(firefox:27487): Gtk-WARNING **: Error loading theme icon 'dialog-warning' for stock: Icon 'dialog-warning' not present in theme Pocillo
没有~/snap/firefox/common/.config/
但是有~/snap/firefox/current/.config/
.
直接使用Firefox创建的配置文件好像会失败
您可以尝试制作一个复制文件夹并使用它。
关于直接选择配置文件失败的原因,您可以在这里查看详细信息:
这个问题似乎与使用 Snap 而不是 apt
安装 Firefox
直接相关。
参考:https://ubuntuforums.org/showthread.php?t=2398478
它一开始就工作,没有特定的配置文件。
不幸的是,如果您使用内置软件包管理器安装 Firefox,它将通过 snap 安装。所以请小心并安装:
sudo apt install firefox
Geckodriver 尝试从与 /home/username/snap/firefox...
不同的目录加载配置文件,因为它未配置为快照安装。如果您仍想使用 snap 安装,因为它提供了 apt 安装不提供的功能(就像我的情况),那么您仍然可以这样做:
from selenium.webdriver.firefox.options import Options
options = Options()
options.add_argument("-profile")
# put the root directory your default profile path here, you can check it by opening Firefox and then pasting 'about:profiles' into the url field
options.add_argument("/home/username/snap/firefox/common/.mozilla/firefox/dhklfoeb.default-18236362302398")
browser=webdriver.Firefox(options=options)