Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Windows equivalent to PyVirtualDisplay

I have written a web scraper for a mate to save him time at work. It is written in Python, using Selenium and opening a Firefox browser.

I have written this code myself on a Linux machine I use PyVirtualDisplay so Firefox doesn't actually open and disturb my work.

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

like image 239
HenryM Avatar asked Apr 07 '17 05:04

HenryM


People also ask

What is Pyvirtualdisplay?

pyvirtualdisplay is a python wrapper for Xvfb, Xephyr and Xvnc.

What is the use of XVFB?

Xvfb (short for X virtual framebuffer) is an in-memory display server for UNIX-like operating system (e.g., Linux). It enables you to run graphical applications without a display (e.g., browser tests on a CI server) while also having the ability to take screenshots.


1 Answers

The reason you can not run PyVirtualDisplay on Windows is that PyVirtualDisplay uses Xvfb as it's display and Xvfb is a headless 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 the Display(visible=True) Or you can set the backend as is shown in the API here.

My recommendation

Don't use PyVirtualDisplay you can use any webdriver such as Chrome driver and just add ChromeOptions with --headless.

Or in your case you use firefox so it would look something like:

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 updated info just have a look here.

Hope this helps you!

like image 132
Moshe Slavin Avatar answered Sep 19 '22 18:09

Moshe Slavin