【问题标题】:Is there a Windows equivalent to PyVirtualDisplay是否有与 PyVirtualDisplay 等效的 Windows
【发布时间】:2017-04-07 05:44:32
【问题描述】:

我为一位伙伴编写了一个网络爬虫,以节省他的工作时间。它是用Python 编写的,使用Selenium 并打开Firefox 浏览器。

我自己在我使用PyVirtualDisplay 的 Linux 机器上编写了这段代码,因此 Firefox 实际上不会打开并干扰我的工作。

如何让它在 Windows PC 上的虚拟显示器中运行?

【问题讨论】:

  • 您是否找到了在 Windows PC 上进行虚拟显示的解决方案? (不使用--headless

标签: python selenium pyvirtualdisplay


【解决方案1】:

你不能在 Windows 上运行 PyVirtualDisplay 的原因是 PyVirtualDisplay 使用 Xvfb 作为它的显示,而 Xvfb 是 X 窗口系统的无头显示服务器,Windows 不使用 X 窗口系统。

不推荐

所以...如果您坚持使用 PyVirtualDisplay,您可以做的是更改 Display(visible=True) 或者您可以设置后端,如 API here 中所示。

我的建议

不要使用PyVirtualDisplay,您可以使用任何网络驱动程序,例如 Chrome 驱动程序,只需添加带有 --headless 的 ChromeOptions。

或者在您的情况下,您使用 Firefox,所以它看起来像:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

options = Options()
options.add_argument("--headless")
driver = webdriver.Firefox(firefox_options=options, executable_path="C:\\Utility\\BrowserDrivers\\geckodriver.exe")
print("Firefox Headless Browser Invoked")
driver.get('http://google.com/')
driver.quit()

如需更多更新信息,请查看here

希望对您有所帮助!

【讨论】:

    猜你喜欢
    • 2023-02-11
    • 2011-11-14
    • 1970-01-01
    • 1970-01-01
    • 2012-09-05
    • 2019-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多