selenium.common.exceptions.WebDriverException: Message: connection refused

前端 未结 7 626
野趣味
野趣味 2020-11-30 09:14

Here is my code:

from selenium import webdriver

browser = webdriver.Firefox()

browser.get(\'http://www.python.org\')

browser.close()

It

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 09:27

    Check your geckodriver.log file (should be in the same directory as python file)

    If it says Error: GDK_BACKEND does not match available displays then install pyvirtualdisplay:

    pip install pyvirtualdisplay selenium
    

    You might need xvfb too:

    sudo apt-get install xvfb # Debian
    
    sudo yum install Xvfb # Fedora
    

    Then try adding this code:

    from pyvirtualdisplay import Display
    display = Display(visible=0, size=(800, 600))
    display.start()
    

    Full example:

    from pyvirtualdisplay import Display
    from selenium import webdriver
    
    display = Display(visible=0, size=(800, 600))
    display.start()
    
    browser = webdriver.Firefox()
    browser.get('http://www.python.org')
    
    browser.close()
    

提交回复
热议问题