使用selenium庫時,報錯WebDriverException: Message: Proces

使用selenium庫時,報錯WebDriverException: Message: Process unexpectedly closed with status 1

檢查當前目錄下的geckodriver.log日誌,如果內容如下:
Error: GDK_BACKEND does not match available displays 或
Error: no DISPLAY environment variable specified
表示沒有可供顯示的環境,因爲是在命令行模式下(無頭模式)試圖啓動firefox。此時需要爲selenium的webdriver.Firefox設置其選項,如下:

from selenium import webdriver
from selenium.webdriver import FirefoxOptions
opts = FirefoxOptions()
opts.add_argument("--headless")
browser = webdriver.Firefox(firefox_options=opts)
browser.get('http://example.com')

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章