Is there a Windows equivalent for PyVirtualDisplay

I wrote a web scraper for an assistant to save him time at work. It is written in Python, using Seleniumand opening the Firefox browser.

I myself wrote this code on a Linux machine, I use PyVirtualDisplayit therefore Firefox does not actually open or break my work.

How can I run it on a virtual display on a Windows PC?

+10
source share
1 answer

The reason you cannot run PyVirtualDisplayon Windows is because PyVirtualDisplay uses Xvfb as it displays, and Xvfb is a dumb display server for the X Window System, Windows does not use the X Window System.

Not recommended

So ... what you can do if you insist on working with PyVirtualDisplay is to change Display(visible=True)Or you can set the backend as shown in the API here .

My recommendation

Do not use; PyVirtualDisplayyou can use any webdriver, such as the Chrome driver, and just add ChromeOptions with --headless.

Or in your case, you use firefox to look something like this:

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()

For more information just look here .

Hope this helps you!

0

Source: https://habr.com/ru/post/1016379/


All Articles