Linux Ubuntu 下安装使用selenium 环境搭建

2021年9月10日 Jerry 4206 2023年12月12日

如何在linux下安装selenium进行环境搭建及使用呢?简单的几个命令就能实现,Ubuntu为例记录一下。

一、安装chrome

sudo apt-get install libxss1 libappindicator1 libindicator7
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb 
google-chrome --version # 查看版本

安装没问题的话,查看版本信息提示如下:

111@ubuntu:/srv/http/csdn/csdndown$ google-chrome --version
Google Chrome 93.0.4577.63

二、下载chromedriver

#执行如下命令(第一条用于获取最新版本号,第二条用于下载):
LATEST=$(wget -q -O - http://chromedriver.storage.googleapis.com/LATEST_RELEASE)
wget http://chromedriver.storage.googleapis.com/$LATEST/chromedriver_linux64.zip

# 解压
unzip chromedriver_linux64.zip

# 修改权限
chmod +x chromedriver

# 可以移动driver 省的指定位置
sudo mv chromedriver /usr/bin/

# 查看版本
./chromedriver --version

安装没毛病的话,查看版本信息提示如下:

./chromedriver --version
ChromeDriver 93.0.4577.63 (ff5c0da2ec0adeaed5550e6c7e98417dac77d98a-refs/branch-heads/4577@{#1135})

三、安装selenium

pip install selenium

四、测试

from selenium import webdriver
# 如果没有将driver移动到 sudo mv chromedriver /usr/bin/ 要指定 driverpath
driverpath = ''       
driver = webdriver.Chrome(executable_path=driverpath)
driver.get("https://www.baidu.com/")
print(driver.title)

附下载地址:

https://chromedriver.storage.googleapis.com/index.html

https://www.chromedownloads.net/chrome64win-stable/

最新webdriver地址:https://googlechromelabs.github.io/chrome-for-testing/


原创文章,转载请注明出处: https://jerrycoding.com/article/linux-selenium

微信
jerry微信赞助
支付宝
jerry支付宝赞助

您尚未登录,暂时无法评论。请先 登录 或者 注册

0 人参与 | 0 条评论