python selenium下载一个合适的chromedriver.exe(稳定版本)
可以使用该脚本来进行下载:
下载前需要安装如下的依赖
requests==2.27.1
selenium==4.14.0
webdriver_manager==4.0.1
下载脚本代码:
import json
import subprocess
import shutil
import os
import time
import zipfileimport requests
from webdriver_manager.core.os_manager import OperationSystemManager
from webdriver_manager.chrome import ChromeDriverManager, ChromeType__all__ = {'download_suit_chrome_driver'
}# 记录固定数据
chrome_json_file = 'chrome_version.json'
chrome_zip = 'chrome_driver.zip'def format_float(num):return '{:.2f}'.format(num)def download_file(name, url):''':param name:下载保存的名称:param url: 下载链接:return:'''headers = {'Proxy-Connection': 'keep-alive'}r = requests.get(url, stream=True, headers=headers)length = float(r.headers['content-length'])f = open(name, 'wb')count = 0count_tmp = 0time1 = time.time()for chunk in r.iter_content(chunk_size=512):if chunk:f.write(chunk)count += len(chunk)if time.time() - time1 > 2:p = count / length * 100speed = (count - count_tmp) / 1024 / 1024 / 2count_tmp = countprint(name + ': ' + format_float(p) + '%' + ' Speed: ' + format_float(speed) + 'M/S')time1 = time.time()f.close()def install_chrome_driver():"""安装chrome浏览器"""try:p = ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install()os.environ['CHROME_DRIVER_PATH'] = pexcept Exception as e:print("error")def get_chromedriver_version(chromedriver_path="chromedriver.exe"):"""获取chrome_driver版本Args:chromedriver_path:Returns:"""try:# 运行Chromedriver,并通过命令行参数获取版本信息result = subprocess.run([chromedriver_path, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)if result.returncode == 0:# 如果成功执行,解析版本信息version = result.stdout.strip()version_list = str(version).split(" ")if len(version_list) == 3:version = version_list[1]return True, versionelse:# 如果执行失败,输出错误信息error_message = result.stderr.strip()return False, f"Error: {error_message}"except Exception as e:return False, f"An error occurred: {str(e)}"def get_chrome_version():"""获取chrome版本Returns:"""try:os_version = OperationSystemManager().get_browser_version_from_os("google-chrome")print(f"os_version:{os_version}")return os_versionexcept Exception as e:return Nonedef get_chrome_version_info(version_info: str):if os.path.exists(chrome_json_file):with open(chrome_json_file) as f:data = f.read()json_data = json.loads(data)if json_data.get(version_info, None) is not None:return True, json_data.get(version_info)else:dict_version_info = {}google_driver_json_url = 'https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json'res = requests.get(google_driver_json_url)res_dict = json.loads(res.text)version_list = res_dict['versions']for version in version_list:downloads_ = version['downloads']if downloads_.get('chromedriver', None) is not None:download_list = downloads_['chromedriver']for data in download_list:if data['platform'] == 'win64':version_place = str(version['version'])version_ = version_place[0:version_place.rfind('.')]dict_version_info[version_] = data['url']with open(chrome_json_file, 'w+') as f:json.dump(dict_version_info, f, indent=4)if dict_version_info.get(version_info, None) is not None:version_url = dict_version_info[version_info]return True, version_urlreturn False, 'error to get'else:dict_version_info = {}google_driver_json_url = 'https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json'res = requests.get(google_driver_json_url)res_dict = json.loads(res.text)version_list = res_dict['versions']for version in version_list:downloads_ = version['downloads']if downloads_.get('chromedriver', None) is not None:download_list = downloads_['chromedriver']for data in download_list:if data['platform'] == 'win64':version_place = version['version']version_ = version_place[0:version_place.rfind('.')]dict_version_info[version_] = data['url']with open(chrome_json_file, 'w+') as f:json.dump(dict_version_info, f, indent=4)if dict_version_info.get(version_info, None) is not None:version_url = dict_version_info[version_info]return True, version_urlreturn False, 'error to get'def download_suit_chrome_driver(chrome_driver_path: str = "chromedriver.exe"):"""下载合适的chrome_driver.exeReturns:"""is_ok, chrome_driver_version = get_chromedriver_version(chrome_driver_path)browser_version = get_chrome_version()if is_ok:if str(chrome_driver_version).count(browser_version) > 0:print(f"当前已是合适的chrome_driver:{chrome_driver_version}")return Trueelse:chrome_driver_big_version = browser_version.split(".")[0]if int(chrome_driver_big_version) < 115:print("下载Chrome-Driver")install_chrome_driver()else:is_get_chrome, version_info = get_chrome_version_info(browser_version)if is_get_chrome:download_url = version_infoprint('ok-remove-0')if os.path.exists(chrome_zip):os.remove(chrome_zip)print('ok-remove-2')download_file(chrome_zip, download_url)print('ok-remove-3')with zipfile.ZipFile(chrome_zip, 'r') as zip_ref:zip_ref.extractall('./')shutil.move('./chromedriver-win64/chromedriver.exe', './chromedriver.exe')if os.path.exists(chrome_zip):os.remove(chrome_zip)else:chrome_driver_big_version = browser_version.split(".")[0]if int(chrome_driver_big_version) < 115:print("下载Chrome-Driver")install_chrome_driver()else:is_get_chrome, version_info = get_chrome_version_info(browser_version)if is_get_chrome:download_url = version_infoprint('ok-remove-0')if os.path.exists(chrome_zip):os.remove(chrome_zip)print('ok-remove-2')download_file(chrome_zip, download_url)print('ok-remove-3')with zipfile.ZipFile(chrome_zip, 'r') as zip_ref:zip_ref.extractall('./')shutil.move('./chromedriver-win64/chromedriver.exe', './chromedriver.exe')if os.path.exists(chrome_zip):os.remove(chrome_zip)if __name__ == '__main__':download_suit_chrome_driver("chromedriver.exe")
调用方式:
download_suit_chrome_driver("xxxxx") ## xxxxxx表示chrome_driver.exe路径(可为空)
github下载链接: https://github.com/huifeng-kooboo/download_chrome_driver
相关文章:
python selenium下载一个合适的chromedriver.exe(稳定版本)
可以使用该脚本来进行下载: 下载前需要安装如下的依赖 requests2.27.1 selenium4.14.0 webdriver_manager4.0.1下载脚本代码: import json import subprocess import shutil import os import time import zipfileimport requests from webdriver_mana…...
RabbitMQ从0到1完整学习笔记一:《基础篇》
目录 启篇 一、初识MQ 1.1 同步调用 1.2异步调用 1.3 技术选型 二、RabbitMQ 架构 2.2 收发消息 2.2.1 交换机 2.2.2 队列 2.2.3 绑定关系 2.2.4 发送消息 2.3 数据隔离 2.3.1 用户管理 2.3.2 virtual host 三、SpringAMQP 3.1 案例入门 3.1.1 导入依赖 3.1.2 消息发送 3.1.2 消…...
什么是时间冒泡?
时间冒泡是指当一个元素触发一个事件时,事件会像水泡一样,从触发元素向它的所有父节点传播,一直到根节点都会接收到此事件 1。如果父元素中注册了相应的事件处理函数,那么尽管事件在子节点触发的,在父元素上注册的事件…...
Go语言入门心法(三): 接口
Go语言入门心法(一) Go语言入门心法(二): 结构体 Go语言入门心法(三): 接口 一:go语言接口认知 Go语言中接口认知升维:解决人生问题的自我引导法则: 复盘思维|结构化思维|金字塔思维|体系化思维|系统化思维 面向对象编程(oop)三大特性: 封装,继承,多态 Go语言中,可…...
leetcode:210. 课程表 II
课程表 II 提示 中等 889 相关企业 现在你总共有 numCourses 门课需要选,记为 0 到 numCourses - 1。给你一个数组 prerequisites ,其中 prerequisites[i] [ai, bi] ,表示在选修课程 ai 前 必须 先选修 bi 。 例如,想要学习课程…...
[MT8766][Android12] 使用谷歌LPA实现ESIM功能的流程
文章目录 开发平台基本信息问题描述实现流程 其他问题 开发平台基本信息 芯片: MT8766 版本: Android 12 kernel: msm-4.19 问题描述 客户需要我们设备支持ESIM功能,5月份的时候在高通6125上面预研过ESIM功能,当时ESIM供应商是Links field,…...
MyBatis-Plus为简化开发而生
简介 MyBatis-Plus 简称 MP是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。 他们的愿景是成为 MyBatis 最好的搭档,就像魂斗罗中的 1P、2P,基友搭配,效率翻倍。 特性 无…...
【翻译】Efficient Data Loader for Fast Sampling-Based GNN Training on Large Graphs
转载请注明出处:小锋学长生活大爆炸[xfxuezhang.cn] 此内容为机器翻译的结果,若有异议的地方,建议查看原文。 机器翻译的一些注意点,比如: 纪元、时代 > epoch工人 > worker火车、培训、训练师 > train Effic…...
OPUS解码器PLC
OPUS解码器支持PLC(Packet Loss Concealment)技术。 在音频通信中,网络丢包是常见的情况。当网络丢失一些音频数据包时,接收端可能无法正常解码并播放这些丢失的音频信号,导致声音中断或质量下降。为了改善这种情况&a…...
Rancher 使用指南
Rancher 使用指南 Rancher 是什么?Rancher 与 OpenShift / Kubesphere 主要区别对比RancherOpenShiftKubesphere 对比 Rancher 和 OpenShift Rancher 安装 Rancher 是什么? 企业级Kubernetes管理平台 Rancher 是供采用容器的团队使用的完整软件堆栈。它解决了管理多个Kuber…...
百度SEO优化全攻略(提高网站排名的5个方面)
百度SEO入门介绍: 随着互联网的不断发展,SEO已经成为网站优化的重要一环。而百度作为中国最大的搜索引擎,其SEO优化更是至关重要。SEO不仅能够提高网站排名,还能够提高网站流量、用户体验以及品牌知名度。因此,掌握百…...
华为云云耀云服务器L实例评测|华为云耀云服务器L实例私有库搭建verdaccio(八)
九、华为云耀云服务器L实例私有库搭建verdaccio: Verdaccio 是一个简单的、零配置本地私有 npm 软件包代理注册表。Verdaccio 开箱即用,拥有自己的小型数据库,能够代理其它注册表(例如 npmjs.org),缓存下载…...
C语言之动态内存管理_柔性数组篇(2)
目录 柔性数组的特点 柔性数组的使用 动态内存函数增容柔性数组模拟实现 柔性数组的优势 今天接着来讲解一下柔性数组知识。 柔性数组的特点 C99中,结构中的最后一个元素允许是未知大小的数组,这就叫做【柔性数组】成员。 结构体中最后一个成员未…...
vue基础
引入vue文件 <div id"app"><!--{{}}插值表达式,绑定vue中的data数据-->{{message}} </div><script src"vue.min.js"></script> <script>new Vue({el:#app,data:{message:Hello Vue}}) </script>单项…...
访问量突破1W,纪念一下~
Mr.kanglong, 继续加油!...
C# 处理TCP数据的类(服务端)
using System; using System.Collections.Generic; using System.Net; using System.Net.Sockets; using System.Threading;namespace TestDemo {/// <summary>/// 处理TCP数据的类(服务端)/// </summary>public class TcpService{/// <s…...
【Jenkins】调用API构建并钉钉通知
文章目录 Jenkins API介绍提交作业带参数的作业API 令牌 Shell调用代码 Jenkins API介绍 Jenkins 提供了远程访问 API。目前它有三种格式: XML JSON Python 远程访问 API 形式为"…/api/" 例如, Jenkins 安装位于https://ci.jenkins.io&a…...
Java NIO三大核心组件
文章目录 一、Buffer1、重要属性2、重要方法1)allocate()创建缓冲区2)put()写入到缓冲区3)flip()翻转4)get()从缓冲区读取5)rewind()倒带6)mark()和reset()7)clear()清空缓冲区8)使用…...
js数据排序方法(sort)?
在JavaScript中,可以使用Array的sort()方法对数据进行排序。下面是一个基本的例子,它展示了如何对一个数组进行升序和降序排序: // 创建一个数字数组 let numbers [2, 9, 1, 5, 8, 6];// 升序排序 let ascending numbers.sort(function(a,…...
若依框架学习笔记_mybatis
一、 在框架中引用的先后顺序 在ruoyi-system的resources下的xml中定义方法在java下的mapper包中引用方法在java下的service包中再引用mapper的方法 二、xml中的写法 标签: resultMap 返回数据sql 查询语句 可包含在其他操作中select 查询insert 插入update 更新…...
day52 ResNet18 CBAM
在深度学习的旅程中,我们不断探索如何提升模型的性能。今天,我将分享我在 ResNet18 模型中插入 CBAM(Convolutional Block Attention Module)模块,并采用分阶段微调策略的实践过程。通过这个过程,我不仅提升…...
智能在线客服平台:数字化时代企业连接用户的 AI 中枢
随着互联网技术的飞速发展,消费者期望能够随时随地与企业进行交流。在线客服平台作为连接企业与客户的重要桥梁,不仅优化了客户体验,还提升了企业的服务效率和市场竞争力。本文将探讨在线客服平台的重要性、技术进展、实际应用,并…...
高等数学(下)题型笔记(八)空间解析几何与向量代数
目录 0 前言 1 向量的点乘 1.1 基本公式 1.2 例题 2 向量的叉乘 2.1 基础知识 2.2 例题 3 空间平面方程 3.1 基础知识 3.2 例题 4 空间直线方程 4.1 基础知识 4.2 例题 5 旋转曲面及其方程 5.1 基础知识 5.2 例题 6 空间曲面的法线与切平面 6.1 基础知识 6.2…...
【Go】3、Go语言进阶与依赖管理
前言 本系列文章参考自稀土掘金上的 【字节内部课】公开课,做自我学习总结整理。 Go语言并发编程 Go语言原生支持并发编程,它的核心机制是 Goroutine 协程、Channel 通道,并基于CSP(Communicating Sequential Processes࿰…...
【决胜公务员考试】求职OMG——见面课测验1
2025最新版!!!6.8截至答题,大家注意呀! 博主码字不易点个关注吧,祝期末顺利~~ 1.单选题(2分) 下列说法错误的是:( B ) A.选调生属于公务员系统 B.公务员属于事业编 C.选调生有基层锻炼的要求 D…...
Axios请求超时重发机制
Axios 超时重新请求实现方案 在 Axios 中实现超时重新请求可以通过以下几种方式: 1. 使用拦截器实现自动重试 import axios from axios;// 创建axios实例 const instance axios.create();// 设置超时时间 instance.defaults.timeout 5000;// 最大重试次数 cons…...
【HTTP三个基础问题】
面试官您好!HTTP是超文本传输协议,是互联网上客户端和服务器之间传输超文本数据(比如文字、图片、音频、视频等)的核心协议,当前互联网应用最广泛的版本是HTTP1.1,它基于经典的C/S模型,也就是客…...
PAN/FPN
import torch import torch.nn as nn import torch.nn.functional as F import mathclass LowResQueryHighResKVAttention(nn.Module):"""方案 1: 低分辨率特征 (Query) 查询高分辨率特征 (Key, Value).输出分辨率与低分辨率输入相同。"""def __…...
无人机侦测与反制技术的进展与应用
国家电网无人机侦测与反制技术的进展与应用 引言 随着无人机(无人驾驶飞行器,UAV)技术的快速发展,其在商业、娱乐和军事领域的广泛应用带来了新的安全挑战。特别是对于关键基础设施如电力系统,无人机的“黑飞”&…...
Git常用命令完全指南:从入门到精通
Git常用命令完全指南:从入门到精通 一、基础配置命令 1. 用户信息配置 # 设置全局用户名 git config --global user.name "你的名字"# 设置全局邮箱 git config --global user.email "你的邮箱example.com"# 查看所有配置 git config --list…...
