centos 7 上如何安装chrome 和chrome-driver

centos 7 上如何安装chrome 和chrome-driver

查找自己的服务器是什么系统

bash 复制代码
cat /etc/os-release

这里以centos linux 7为例

下载google-chrome安装包

bash 复制代码
wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm

安装chrome

bash 复制代码
sudo yum localinstall google-chrome-stable_current_x86_64.rpm 

最后显示complete就表示安装完成了

查看安装版本

bash 复制代码
google-chrome --version 

安装selenium

bash 复制代码
pip install selenium 

用于后续相关代码,方便进行测试

安装chrome-driver

bash 复制代码
 sudo yum install chromedriver 

使用which 查找chromedriver 被安装的位置,将其放到/usr/bin/ 目录下,which找不到的话,可以用下面的命令:

bash 复制代码
sudo find / -name chromedriver

测试相关python代码

bash 复制代码
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()
相关推荐
dingdingfish24 分钟前
TLPI 第52章 读书笔记:POSIX Message Queues
linux·mq·ipc·posix·message·tlpi
wacsii1 小时前
【Linux进程(五)】进程控制全解析:从创建、终止、等待到程序替换
linux·服务器
七夜zippoe2 小时前
Nexent Linux 部署:用 deploy.sh
linux·服务器·docker·部署·ai智能体·nexent
去码头整点薯条982 小时前
NFS服务器
linux·运维·服务器
蜗牛一步步往上爬3 小时前
第一章 初识Linux shell
linux·运维·服务器
拂拉氏3 小时前
【知识讲解】 Linux线程中锁的认识
linux·互斥锁
无足鸟ICT3 小时前
【RHCA+】系统调优配置文件
linux·服务器
时间的拾荒人5 小时前
Shell 脚本核心语法详解(下篇):流程控制、函数、重定向与文件包含
linux·运维·服务器·bash·脚本编程
蜗牛一步步往上爬5 小时前
第四章 更多的bash shell命令
linux·开发语言·bash