Ubuntu 无界面使用selenium chrome + headless
2023-09-11 14:15:15 时间
Ubuntu 无界面使用selenium chrome + headless
1. 安装 selenium :
sudo pip install selenium
2. 安装 chromdriver: 进入 淘宝镜像源 下载 chromdriver, 可以查看 notes.txt 文件,看chrome 和ChromDriver 两者相对应的兼容版本
下载地址:https://npm.taobao.org/mirrors/chromedriver
3. 下载chrome : 下载 chromedriver_linux64.zip
下载地址:https://www.slimjet.com/chrome/google-chrome-old-version.php
4. 将 chromdriver 文件放到线上服务器 /usr/bin/ 下(首先先解压压缩包) ,将google-chrome-stable_current_amd64.deb上传线上服务器(通过下面的命令进行解压)
5. 安装chrome,执行如下命令:
sudo dpkg -i google-chrome*.deb
sudo apt-get install -f
google-chrome --version # 查看版本
6. 编写测试脚本
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--no-sandbox') # 这个配置很重要
client = webdriver.Chrome(chrome_options=chrome_options, executable_path='/usr/bin/chromedriver') # 如果没有把chromedriver加入到PATH中,就需要指明路径
client.get("https://www.baidu.com")
print (client.page_source.encode('utf-8'))
client.quit()
相关文章
- 【Ubuntu】ubuntu物理机安装方法:U盘安装
- Mouse Stroke——Chrome鼠标手势扩展
- Linux下安装chrome和chromedriver
- Ubuntu 14 Chrome字体设置备份
- Ubuntu 14 安装 Chrome/Chromium flash播放器
- js/bat批处理调用谷歌浏览器chrome批量打开网页测试web性能
- ubuntu 安装 Chrome浏览器
- 解决Chrome关联Html文件图标显示为空白
- chrome 低版本的background-attachment: fixed问题
- EasyNVR网页摄像机无插件H5、谷歌Chrome直播方案使用详情功能-通道配置Excel导入导出
- loadrunner录制chrome脚本:页面无响应
- javascript:每次只加载3个页面的幻灯(chrome 105.0.5195.125)
- Chrome开发者工具里的一个隐藏技能:chrome://net-internals
- 一个好用的便利设置浏览器代理的Chrome扩展应用
- 使用Chrome开发者工具研究JavaScript的垃圾回收机制
- ubuntu下安装google-chrome遇到的那些问题和解决方案,手把手教你安装
- Ubuntu中使用sudo执行命令提示:ubuntu is not in the sudoers file. This incident will be reported.
- ubuntu 16.04 tightvncserver VNC 安装配置,安装xrdp,x11vnc、Ubuntu 18.04
- Ubuntu:成功解决ubuntu使用su切换root出现Authentication failure用户时认证失败