使用geckodriver.exe在freebsd中设置selenium时出现问题



我在freebsd中设置程序时遇到问题。我试着用壁虎驱动器。我尝试32位和64位,下载链接在这里https://github.com/mozilla/geckodriver/releases

文档链接

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"usrhomemyuserNamegeckodriver.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"usrhomemyuserNamegeckodriver.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: 'usrhomemyuserNamegeckodriver.exe' executable needs to be in PATH.

我尝试像这个一样更改链接

driver = Firefox(executable_path="usrhomemyuserNamegeckodriver.exe", options=options)

或者像这个

driver = Firefox(executable_path='usrhomemyuserNamegeckodriver.exe', options=options)

或者像这个

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

但仍然存在相同的错误。请帮帮我,将感谢所有的帮助

当您在freebsd环境中使用Selenium时,您需要使用GeckoDriver从mozilla/GeckoDriver页面中卸载以下任一项:

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

此外,在通过GeckoDriver的绝对路径时,您需要放下扩展部分,即.exe。实际上,你的代码块将是:

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

相关内容

最新更新