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

金融服务网站建设如何推销网站

金融服务网站建设,如何推销网站,我公司网站开发技术优势,体育投注网站开发以前通过ChromeDriverManager().install()的方式自动下载驱动的方式,现在行不通了,访问不通下载网址,会报错:requests.exceptions.ConnectionError: Could not reach host. Are you offline? 所以想着换一个下载地址和方式&…

以前通过ChromeDriverManager().install()的方式自动下载驱动的方式,现在行不通了,访问不通下载网址,会报错:requests.exceptions.ConnectionError: Could not reach host. Are you offline?

所以想着换一个下载地址和方式,通过国内的镜像https://registry.npmmirror.com/binary.html?path=chrome-for-testing/下载。

通过接口返回分析发现该网站获取驱动版本的地址为:https://registry.npmmirror.com/-/binary/chrome-for-testing/ ,最终的下载地址前缀为 https://cdn.npmmirror.com/binaries

于是有了下面 的代码,通过windowsAPI获取安装的浏览器的版本,通过上面的地址获取浏览器驱动版本列表信息,找到与浏览器大版本号相同的最新版本的驱动版本,拼接成最终的下载地址。下载驱动压缩包,用解压缩出来的驱动exe文件替换原来的旧文件,然后删除解压缩文件和下载的压缩文件。

"""
根据浏览器版本,更新驱动为对应版本的驱动文件
pip install requests
pip install pywin32
"""import os
import zipfile
import requests
from win32com import client
import shutildef get_version_by_path(exe_path):"""通过谷歌浏览器的安装路径下的.exe获取浏览器版本exe_path 浏览器exe程序文件完整路劲,如:"C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe""""# 判断路径文件是否存在if not os.path.isfile(exe_path):raise FileNotFoundError(f"{exe_path} is not found.")version = client.Dispatch('Scripting.FileSystemObject').GetFileVersion(exe_path)return version.strip()def get_download_url(version, browser_name='chrome'):""" 获取与版本适配的驱动文件的下载地址 version为浏览器版本browsern_name为浏览器名称"""download_url = 'https://cdn.npmmirror.com/binaries'root = 'https://registry.npmmirror.com/-/binary/'chrome_path = 'chrome-for-testing/'edge_path = 'edgedriver/'gecko_path = 'geckodriver/'version_url = root + chrome_pathif browser_name == 'edge':version_url = root + edge_path# 获取与当前版本匹配的最大版本的下载地址response = requests.get(url=version_url)if response.status_code == 200:version_list = eval(response.text)for i in range(len(version_list)):dic = version_list[i]if int(dic['name'].split('.')[0]) > int(version.split('.')[0]):driver_version = version_list[i - 1]['name']if browser_name == 'chrome':download_url = f'{download_url}/chrome-for-testing/{driver_version}win64/chromedriver-win64.zip'if browser_name == 'edge':download_url = f'{download_url}/edgedriver/{driver_version}edgedriver_win64.zip'return download_urldef download_driver(url, file_path, browser_name='chrome'):""" 下载驱动文件到指定路径url 为文件下载地址filepath 为文件保存下载文件的文件夹"""driver_file = 'chromedriver.exe'if browser_name == 'edge':driver_file = 'msedgedriver.exe'# 通过requests下载文件save_path = f"{file_path}{os.sep}{url.split('/')[-1]}"response = requests.get(url, stream=True)response.raise_for_status()with open(save_path, "wb") as file:for chunk in response.iter_content(chunk_size=16384):file.write(chunk)# 如果原来存在驱动文件,则先删除原有的驱动文件if os.path.exists(f"{file_path}{os.sep}{driver_file}"):os.remove(f"{file_path}{os.sep}{driver_file}")# 解压下载的压缩文件,并将驱动文件复制到filepath下with zipfile.ZipFile(save_path, 'r') as zip_file:file_list = zip_file.namelist()for file in file_list:if file.endswith(driver_file):zip_file.extract(file, path=file_path)if '/' in file:shutil.copy(f"{file_path}{os.sep}{file}", f"{file_path}{os.sep}{driver_file}")shutil.rmtree(f"{file_path}{os.sep}{file.split('/')[0]}")  # 删除解压后的文件夹breakos.remove(save_path)  # 删除下载的压缩文件def update_driver(driver_path, browser_name, browser_exe_file):"""更新驱动文件为当前浏览器版本对应的驱动driver_path 为保存驱动文件的路径browser_name 为浏览器的名称browser_exe_file 为浏览器安装路径下的.exe文件的完整文件名"""browser_version = get_version_by_path(browser_exe_file)download_url = get_download_url(browser_version, browser_name)download_driver(download_url, driver_path, browser_name)if __name__ == '__main__':driver_path = './'browser_name = 'chrome'browser_exe = "C:/Program Files/Google/Chrome/Application/chrome.exe"update_driver(driver_path, browser_name, browser_exe)
http://www.khdw.cn/news/53869.html

相关文章:

  • 苏州专业做网站公司哪家好网站推广的工作内容
  • 有没有免费查企业信息的软件关键词优化软件哪家好
  • 兰州模板型网站建设推广一般收多少钱
  • 阜宁做网站哪家好厦门最好的seo公司
  • 淘宝这种网站怎么做的?什么叫外链
  • 软件开发流程八个步骤及介绍霸屏seo服务
  • wordpress music冯耀宗seo视频教程
  • 网站官网设计规范电脑培训课程
  • 服装网站建设的需求班级优化大师是干什么用的
  • wordpress百度网站地图今日新闻 最新消息 大事
  • 超链接网站图片怎么在记事本上做怎么注册电商平台
  • 建设网站专业昆明优化网站公司
  • 建湖做网站哪家公司好长沙 建站优化
  • 毕业设计做网站用php好吗上海优化关键词的公司
  • 网站可以跳转备案吗天桥区seo全网宣传
  • 响应式网站新闻部分怎么做站长工具服务器查询
  • 市住房住房城乡建设委官方网站win7系统优化大师
  • 深圳网站建设吗子域名网址查询
  • 如何做网站收录百度权重1
  • 未来网站建设想法独立站推广
  • 南通网站建设百度推广关键词越多越好吗
  • 中国建设银行网站简介100种找客户的方法
  • wordpress大型网站b站视频推广网站动漫
  • 了解网站建设管理直接进网站的浏览器
  • 手机视频网站建设百度一下你就知道移动官网
  • 支付宝手机网站签约百度app下载并安装最新版
  • dede英文网站网店如何做推广
  • 杭州滨江区抖音seo行情宁波seo优化流程
  • 教做详情页的网站百度网址大全设为主页
  • 网站开发合同审核要点凡科建站多少钱