cat /etc/os-release
这里以centos linux 7
为例
wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
sudo yum localinstall google-chrome-stable_current_x86_64.rpm
最后显示complete就表示安装完成了
google-chrome --version
pip install selenium
用于后续相关代码,方便进行测试
sudo yum install chromedriver
使用which 查找chromedriver 被安装的位置,将其放到/usr/bin/
目录下,which找不到的话,可以用下面的命令:
sudo find / -name chromedriver
from selenium import webdriver
from selenium import webdriver as web
from selenium.webdriver.common.by import By
import time
import os
import urllib
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
options = web.ChromeOptions()
options.add_argument('--ignore-certificate-errors-spki-list')
options.add_argument('--ignore-certificate-errors')
options.add_argument('--ignore-ssl-errors')
options.add_argument('--headless')
# Enter path of chromedriver executable file
s = Service('/usr/bin/chromedriver')
driver = webdriver.Chrome(options=options,service=s)
wait = WebDriverWait(driver,5)
driver.get("https://www.baidu.com")
driver.quit()