使用 geckodriver.exe 在 freebsd 中设置 selenium 的问题

Problem with set up selenium in freebsd using geckodriver.exe

我在 freebsd 中设置程序时遇到问题。我尝试使用 geckodriver。我试试32位和64位,下载link在这里https://github.com/mozilla/geckodriver/releases

文档link

https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Headless_mode

我的代码

from selenium.webdriver import Firefox
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support import expected_conditions as expected
from selenium.webdriver.support.wait import WebDriverWait

options = Options()
options.add_argument('-headless')
driver = Firefox(executable_path=r"usr\home\myuserName\geckodriver.exe", options=options)
driver.get("https://www.verivox.de/stromvergleich/vergleich/#/?plz=10555&persons=on&usage=3500&bonus=OnlyCompliant&profile=H0&product=electricity&source=1&q=WzYsMCwxLDEsMSwxLDEsMiwyMCwwLDEsNzQxMTIyLCI3MTA4NSIs>
allheader=WebDriverWait(driver,20).until(expected.visibility_of_all_elements_located((By.CSS_SELECTOR,"li[class='result-item'] .result-name-area>.result-name")))
for header in allheader:
     print("Header: " + header.text)

我收到错误

Traceback (most recent call last):
  File "/home/myuserName/.local/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 76, in start
    stdin=PIPE)
  File "/usr/local/lib/python3.7/subprocess.py", line 800, in __init__
    restore_signals, start_new_session)
  File "/usr/local/lib/python3.7/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'usr\home\myuserName\geckodriver.exe': 'usr\home\myuserName\geckodriver.exe'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "skriptas.py", line 10, in <module>
    driver = Firefox(executable_path=r"usr\home\myuserName\geckodriver.exe", options=options)
  File "/home/myuserName/.local/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
    self.service.start()
  File "/home/myuserName/.local/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'usr\home\myuserName\geckodriver.exe' executable needs to be in PATH.

我试试这样改link

driver = Firefox(executable_path="usr\home\myuserName\geckodriver.exe", options=options)

或者像这样

driver = Firefox(executable_path='usr\home\myuserName\geckodriver.exe', options=options)

或者像这样

driver = Firefox(executable_path=r'usr/home/myuserName/geckodriver.exe', options=options)

但还是一样的错误。请帮助我,所有帮助将不胜感激

您正在使用 in freebsd environment you need to use the GeckoDriver untaring either of the following from mozilla / geckodriver 页面:

  • geckodriver-v0.28.0-linux32.tar.gz
  • geckodriver-v0.28.0-linux64.tar.gz

此外,在传递 绝对路径 时,您需要删除扩展部分,即 .exe。实际上,您的代码块将是:

driver = Firefox(executable_path='/path/to/geckodriver', options=options)