1.进入linux,首先安装谷歌浏览器,如果有的话,这步骤可以直接跳过。
方法:
yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
/usr/bin/google-chrome-stable -v //查看
/usr/bin/google-chrome-stable status
安装依赖:
yum install -y mesa-libOSMesa-devel gnu-free-sans-fonts wqy-zenhei-fonts
2.查看安装的谷歌浏览器版本号
google-chrome –version
3.安装对应版本号的chromedriver
http://chromedriver.storage.googleapis.com/index.html
wget http://chromedriver.storage.googleapis.com/106.0.5249.61/chromedriver_linux64.zip
4.解压chromedriver
如果没有unzip,那就先安装unzip
apt-get install unzip
如果有的话,就直接可以开始解压
unzip chromedriver_linux64.zip
5.切换路径
mv chromedriver /usr/bin/
6.给予执行权限
chmod +x /usr/bin/chromedriver
7.测试代码是否可以正常运行
#!/usr/bin/python3
#coding:utf-8
from selenium import webdriver
ch_options = webdriver.ChromeOptions()
#为Chrome配置无头模式
ch_options.add_argument("--headless")
ch_options.add_argument('--no-sandbox')
ch_options.add_argument('--disable-gpu')
ch_options.add_argument('--disable-dev-shm-usage')
# 在启动浏览器时加入配置
dr = webdriver.Chrome(options=ch_options)
#这是测试网站
url = "https://www.baidu.com"
dr.get(url)
#打印源码
print(dr.page_source)
如果可以正常运行,说明安装成功,selenium也可以正常使用了。
发布者:小站,转转请注明出处:http://blog.gzcity.top/4792.html
评论列表(2条)
[…] http://blog.gzcity.top/4792.html […]
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.