当前位置: 首页 > news >正文

ubuntu24.04安装selenium、edge、msedgedriver

实验环境:kaggle notebook、colab notebook

1、安装edge

!wget https://packages.microsoft.com/repos/edge/pool/main/m/microsoft-edge-stable/microsoft-edge-stable_138.0.3351.121-1_amd64.deb?brand=M102!sudo dpkg -i microsoft-edge-stable_138.0.3351.121-1_amd64.deb?brand=M102

2、安装chromedriver

!wget https://msedgedriver.microsoft.com/138.0.3351.121/edgedriver_linux64.zip!unzip edgedriver_linux64.zip!sudo mv msedgedriver /usr/local/bin

3、安装selenium

!pip install selenium

4、测试脚本(jupyter notebook版,无头浏览器模式)

import tempfile
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from selenium.webdriver.edge.options import Options
#from webdrivermanager_cn import ChromeDriverManager
import time# 自动下载驱动
#driver_path = ChromeDriverManager().install()# 创建临时用户数据目录
user_data_dir = tempfile.mkdtemp()# 设置 Chrome 启动参数
options = Options()
options.add_argument(f"--user-data-dir={user_data_dir}")
options.add_argument("--no-sandbox")          # Linux 通常需要
options.add_argument("--disable-dev-shm-usage")  # Linux 通常需要
options.add_argument("--headless")            # 如不需要图形界面,可添加此项# 启动浏览器
service = Service(executable_path='/usr/local/bin/msedgedriver')
driver = webdriver.Edge(service=service, options=options)# 使用浏览器
driver.get("https://www.baidu.com")
print(driver.title)
time.sleep(3)
#截屏
driver.save_screenshot(filename="baidu.png")
time.sleep(3)driver.quit()

http://www.lryc.cn/news/608681.html

相关文章:

  • 大语言模型的解码策略:贪婪解码与波束搜索
  • 记一次v-if和key错误使用,导致vue2的内存爆炸修复!
  • 音视频学习(五十):音频无损压缩
  • Arrays.asList() add方法报错java.lang.UnsupportedOperationException
  • Apache Shenyu 本地启动及快速入门
  • 【abc417】E - A Path in A Dictionary
  • HTTPS的概念和工作过程
  • Kazam产生.movie.mux后恢复视频为.mp4
  • Transformer模型用于MT信号相关性预测与分析
  • 知识蒸馏 - 基于KL散度的知识蒸馏 HelloWorld 示例 采用PyTorch 内置函数F.kl_div的实现方式
  • 【C++】封装,this指针
  • 个人自用----c语言指针复习(malloc)
  • 大语言模型涉及的一些概念(持续更新)
  • 安卓加固脱壳
  • 1.8 axios详解
  • Axios介绍
  • 超声波泄露传感器
  • SpringBoot3.x入门到精通系列:2.6 整合 Redis 详解
  • Python 基础语法(一):从常量到运算符
  • jvm之jconsole的使用
  • MySQL连接算法和小表驱动大表的原理
  • 初识prometheus
  • Selenium Web 自动化
  • 【软考中级网络工程师】知识点之 RIP 协议
  • 华为智能家居与Spring人工智能
  • 决策树学习全解析:从理论到实战
  • C++手撕基于ID3算法的决策树
  • 著作权登记遇难题:创作者如何突破确权困境?
  • 自动驾驶中的传感器技术19——Camera(10)
  • ELECTRICAL靶场