美文网首页
centos7 安装chromedriver

centos7 安装chromedriver

作者: 掘金_蒋老湿 | 来源:发表于2020-06-23 18:05 被阅读0次
  1. 到如下网址查找匹配的chrome版本, 我的是这个83.0.4103.
    https://npm.taobao.org/mirrors/chromedriver/
image.png
  1. 下载并解压
wget https://npm.taobao.org/mirrors/chromedriver/83.0.4103.14/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
  1. 添加Chromedriver 软链接
    比如Chromedriver的位置为 /opt/chromedriver
ln -s /opt/chromedriver /usr/bin/chromedriver
  1. 安装完成后,可保存以下py文件进行测试
# -*- coding:utf-8 -*-
 
from selenium import webdriver
 
options = webdriver.ChromeOptions()
options.add_argument('--headless')  # 确保无头
options.add_argument('--disable-gpu')  # 无需要gpu加速
options.add_argument('--no-sandbox')  # 无沙箱
driver = webdriver.Chrome(executable_path="/root/chromedriver", chrome_options=options)  # 添加软链接后是不需要写路径的
 
driver.get("https://www.baidu.com")
print(driver.page_source)
driver.quit()

相关文章

网友评论

      本文标题:centos7 安装chromedriver

      本文链接:https://www.haomeiwen.com/subject/vrnhfktx.html