Install Xvfb (can solve qt error)
yum update
yum install Xvfb
yum -install libXfont
yum install xorg-x11-fonts*
Just execute the xvfb-run program.
Install chrome
vi /etc/yum.repos.d/google-chrome.repo
Write:
[google-chrome]
name=google-chrome
baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch
enabled=1
gpgcheck=1
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
yum update
yum install google-chrome-stable
Add a soft link
which google-chrome-stable
ln -s 路径 /bin/chrome
Install chromedrive
View version
chrome -version
Download the corresponding driver
https://sites.google.com/a/chromium.org/chromedriver/homedownload chromedriver
Add permission soft link
chmod +x chromedriver
sudo mv -f chromedriver /usr/local/share/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
Install selenium, pyvirtualdisplay
pip install selenium
pip install pyvirtualdisplay
Set chrome to use no interface display
options = webdriver.ChromeOptions()
options.add_argument('--headless')
browser = webdriver.Chrome(chrome_options=options)
demo
from selenium import webdriver
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
options = webdriver.ChromeOptions()
options.add_argument('--headless')
browser = webdriver.Chrome(chrome_options=options)
browser.get("http://www.baidu.com")
print(browser.page_source)
browser.quit()
display.stop()
Transfer from: https://blog.csdn.net/ZincZhang/article/details/79797847