相同的设置在另一台Linux服务器上运行。我刚刚迁移到AWS(Centos 7),现在我正面临这个问题。
我的代码:
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(1366, 768))
display.start()
browser = webdriver.Firefox()
browser.set_window_size(1366, 768)
browser.get('http://www.vionblog.com/')
browser.set_script_timeout(30)
browser.set_page_load_timeout(30) # seconds
browser.save_screenshot('vionblog.png')
browser.quit()
display.stop()
错误:
Traceback (most recent call last): File "test.py", line 11, in <module> browser = webdriver.Firefox() File "/usr/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 158, in __init__ keep_alive=True) File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__ self.start_session(desired_capabilities, browser_profile) File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute self.error_handler.check_response(response) File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: connection refused
答案 0 :(得分:0)
您需要从此site下载 GeckoDriver 二进制文件,将其放置在系统中的任何位置,并明确提及 GeckoDriver 二进制文件的位置。以下代码行启动 Web浏览器客户端:
browser = webdriver.Firefox(executable_path=r'C:\path\to\geckodriver.exe')