linux上面运行selenium

首先下载依赖

yum install mesa-libOSMesa-devel gnu-free-sans-fonts wqy-zenhei-fonts

然后下载安装chrome

yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm

查看chrome版本号

google-chrome --version

根据版本号下载对应的驱动

https://registry.npmmirror.com/binary.html?path=chromedriver/
wget https://chromedriver.storage.googleapis.com/2.38/chromedriver_linux64.zip
将解压好的文件放在/usr/bin目录下,并且给chromedrive增加可以执行权限
解压
unzip chromedriver_linux64.zip
mv chromedriver /usr/bin/

给予执行权限
chmod +x /usr/bin/chromedriver

运行代码测试

from selenium import webdriver
 
options = webdriver.ChromeOptions()
options.add_argument('--headless')  #设置无头浏览器请求模式
options.add_argument("--disable-extensions")
options.add_argument("--disable-gpu")
options.add_argument("--no-sandbox") # linux中不写会报错
driver = webdriver.Chrome(options=options)
 
driver.get('https://www.baidu.com')
print(driver.page_source)

#######

posted @   技术改变命运Andy  阅读(376)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
历史上的今天:
2021-10-20 Mac tshark 报错:command not found: tshark
2021-10-20 android手机安装busybox步骤
2020-10-20 20-crm项目-kingadmin,开发批量生成上课记录和学员课程页面
点击右上角即可分享
微信分享提示