- 安装python3及相关依赖
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-c++ openssl-devel zlib zlib-devel python3 python3-devel -y
- 安装chrome
2.1 添加repo源
sudo vi /etc/yum.repos.d/google.repo
在打开的空文件中填入以下内容
[google]
name=Google-x86_64
baseurl=http://dl.google.com/linux/rpm/stable/x86_64
enabled=1
gpgcheck=0
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
1.2 yum安装
sudo yum update -y
sudo yum install google-chrome-stable -y
安装之后查看google-chrome的版本
google-chrome -version
3.安装谷歌驱动 下载地址:http://npm.taobao.org/mirrors/chromedriver/ 或者使用https://chromedriver.storage.googleapis.com/index.html 下载驱动时需要与google-chrome的版本尽量保持一致
wget https://chromedriver.storage.googleapis.com/90.0.4430.24/chromedriver_linux64.zip
下载完成后,解压
4.安装selenium
pip install selenium
5.python测试
python3 test.py
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--no-sandbox')
url="https://blog.csdn.net/"
brower=webdriver.Chrome(executable_path="./chromedriver", options=chrome_options)
brower.get(url)
source = brower.page_source
print(source)
brower.quit()
|