安裝Xvfb (可解決qt報錯)
yum update
yum install Xvfb
yum -install libXfont
yum install xorg-x11-fonts*
執行 xvfb-run 程序即可。
安裝chrome
vi /etc/yum.repos.d/google-chrome.repo
寫入:
[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
添加軟連接
which google-chrome-stable
ln -s 路徑 /bin/chrome
安裝chromedrive
查看版本
chrome -version
下載對應驅動
https://sites.google.com/a/chromium.org/chromedriver/home下載chromedriver
添加權限 軟連接
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
安裝selenium、pyvirtualdisplay
pip install selenium
pip install pyvirtualdisplay
設置chrome使用無界面顯示
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()