linux下后台运行selenium
linux下后台运行selenium:
安装浏览器:
Google Chrome 77.0.3865.75configure
ChromeDriver 77.0.3865.40
pyautogui:
安装Xvfb后启动虚拟显示器
Xvfb -ac :0 -screen 0 1920x1080x24
export DISPLAY=:0
FAQ:
Q: NOTE: You must install tkinter on Linux to use MouseInfo. Run the following: sudo apt-get install python3-tk python3-dev
A: python3.6安装tk/tcl:
1.下载tcl包和tk包 https://www.tcl.tk/software/tcltk/download.html
2.安装包https://blog.csdn.net/and_december/article/details/71178539
运行脚本
# coding:utf-8
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--remote-debugging-port=9222')
browser = webdriver.Chrome(chrome_options=chrome_options)
driver.get("https://www.baidu.com")