centos安装chromedriver并使用
yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
# 查看安装的版本
chromedriver -version
根据上方查出的版本,在https://npm.taobao.org/mirrors/chromedriver中找到合适的安装包
wget http://npm.taobao.org/mirrors/chromedriver/89.0.4389.23/chromedriver_linux64.zip
# 解压即可使用
unzip chromedriver_linux64.zip
mv chromedriver /usr/local/bin/
使用selenium
from selenium import webdriver
driver_path = '/usr/local/bin/chromedriver'
url = 'www.baidu.com'
option = webdriver.ChromeOptions()
option.add_argument('headless')
option.add_argument('no-sandbox')
option.add_argument('disable-dev-shm-usage')
driver = webdriver.Chrome(driver_path, chrome_options=option)
driver.get(url)
content = driver.page_source
driver.close()
print (content)
还没有评论,来说两句吧...