当我执行以下代码时
from selenium import webdriver
browser = webdriver.Firefox()
我收到以下错误
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/home/rohit/.local/lib/python3.4/site-packages/selenium/webdriver/firefox/webdriver.py", line 103, in __init__
self.binary, timeout)
File "/home/rohit/.local/lib/python3.4/site-packages/selenium/webdriver/firefox/extension_connection.py", line 51, in __init__
self.binary.launch_browser(self.profile, timeout=timeout)
File "/home/rohit/.local/lib/python3.4/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
self._wait_until_connectable(timeout=timeout)
File "/home/rohit/.local/lib/python3.4/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 98, in _wait_until_connectable
raise WebDriverException("The browser appears to have exited "
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.
我做错了什么。
答案 0 :(得分:0)
看起来你需要安装Xvfb然后pyvirtualdisplay。 相反,你可以使用Xephyr或Xvnc。
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(1024, 768))
display.start()
browser = webdriver.Firefox()