簡體   English   中英

使用 geckodriver.exe 在 freebsd 中設置 selenium 的問題

[英]Problem with set up selenium in freebsd using geckodriver.exe

我在 freebsd 中設置我的程序時遇到問題。 我嘗試使用 geckodriver。 我嘗試了 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"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.

我嘗試像這樣更改鏈接

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)

但仍然是同樣的錯誤。 請幫助我,所有幫助將不勝感激

當您在freebsd環境中使用Selenium 時,您需要使用GeckoDrivermozilla / 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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM