后台运行python程序(gui and not gui)
后台运行python程序(gui and not gui)
依赖说明:
- xvfb:虚拟设备,即一个虚拟的X服务器环境 [主要适用于Run Gui program on Server OS]
- pyvirtualdisplay:a python wrapper for Xvfb, Xephyr and Xvnc
依赖安装:
1 2 |
sudo apt-get install xvfb pip install pyvirtualdisplay |
示例代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#!/usr/bin/env python from pyvirtualdisplay import Display from selenium import webdriver display = Display(visible=0, size=(800, 600)) display.start() # now Firefox will run in a virtual display. # you will not see the browser. browser = webdriver.Firefox() browser.get('https://cpp.cloudcpp.com') print browser.title browser.quit() display.stop() |
Copyright:cpp.cloudcpp.com Share、Open- C/C++程序员之家