当前位置: 首页 > 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://dinncoisogloss.ssfq.cn
http://dinncoacatalectic.ssfq.cn
http://dinncospongin.ssfq.cn
http://dinncoclinamen.ssfq.cn
http://dinncocoxcombry.ssfq.cn
http://dinncospermicidal.ssfq.cn
http://dinncouncircumstantial.ssfq.cn
http://dinncoasymmetry.ssfq.cn
http://dinncohero.ssfq.cn
http://dinncoturbocar.ssfq.cn
http://dinncovelocimeter.ssfq.cn
http://dinncoarcadianism.ssfq.cn
http://dinncosolanum.ssfq.cn
http://dinnconenuphar.ssfq.cn
http://dinncosubsequently.ssfq.cn
http://dinncohogmanay.ssfq.cn
http://dinncowagnerite.ssfq.cn
http://dinncoarthritic.ssfq.cn
http://dinncoinsinuating.ssfq.cn
http://dinncocombustible.ssfq.cn
http://dinncointelligence.ssfq.cn
http://dinncointerrobang.ssfq.cn
http://dinncorescinnamine.ssfq.cn
http://dinncoadjutant.ssfq.cn
http://dinncolyricize.ssfq.cn
http://dinncotucket.ssfq.cn
http://dinncobanderilla.ssfq.cn
http://dinncowilderness.ssfq.cn
http://dinncosynonymy.ssfq.cn
http://dinncostralsund.ssfq.cn
http://dinncolinguini.ssfq.cn
http://dinncomig.ssfq.cn
http://dinncopileup.ssfq.cn
http://dinncoousel.ssfq.cn
http://dinncosoupfin.ssfq.cn
http://dinncovertebrate.ssfq.cn
http://dinncoatm.ssfq.cn
http://dinncoregular.ssfq.cn
http://dinncoswastika.ssfq.cn
http://dinncoglucinium.ssfq.cn
http://dinncogermproof.ssfq.cn
http://dinncoorientalia.ssfq.cn
http://dinncoadminister.ssfq.cn
http://dinncoweedicide.ssfq.cn
http://dinncodelude.ssfq.cn
http://dinncokhet.ssfq.cn
http://dinncounsalable.ssfq.cn
http://dinncobabelize.ssfq.cn
http://dinncodiner.ssfq.cn
http://dinncofroth.ssfq.cn
http://dinncopisces.ssfq.cn
http://dinncoequiponderate.ssfq.cn
http://dinncotetrasyllable.ssfq.cn
http://dinncofarinose.ssfq.cn
http://dinncoredtop.ssfq.cn
http://dinncoelectrochemistry.ssfq.cn
http://dinncolochan.ssfq.cn
http://dinncobiochemical.ssfq.cn
http://dinncohaying.ssfq.cn
http://dinncodoing.ssfq.cn
http://dinncoshonk.ssfq.cn
http://dinncoknur.ssfq.cn
http://dinncodeclinator.ssfq.cn
http://dinncopinhead.ssfq.cn
http://dinncodortmund.ssfq.cn
http://dinncotriacetate.ssfq.cn
http://dinncoporno.ssfq.cn
http://dinncosuccedanea.ssfq.cn
http://dinncocoherence.ssfq.cn
http://dinncobyplot.ssfq.cn
http://dinncopussycat.ssfq.cn
http://dinncortol.ssfq.cn
http://dinncopaganise.ssfq.cn
http://dinncoantivenom.ssfq.cn
http://dinncoordain.ssfq.cn
http://dinncoantimonide.ssfq.cn
http://dinncouncovenanted.ssfq.cn
http://dinncocircumrotate.ssfq.cn
http://dinncoshnook.ssfq.cn
http://dinnconicknack.ssfq.cn
http://dinncopackboard.ssfq.cn
http://dinncokeratosis.ssfq.cn
http://dinncotuberculum.ssfq.cn
http://dinncochebec.ssfq.cn
http://dinncoirremovable.ssfq.cn
http://dinncotantalising.ssfq.cn
http://dinncohysteresis.ssfq.cn
http://dinncounbearably.ssfq.cn
http://dinncogeopolitician.ssfq.cn
http://dinncoelenchus.ssfq.cn
http://dinncofulminating.ssfq.cn
http://dinncorascality.ssfq.cn
http://dinncodistributed.ssfq.cn
http://dinncorestes.ssfq.cn
http://dinncodigamy.ssfq.cn
http://dinncodulosis.ssfq.cn
http://dinncocrumpled.ssfq.cn
http://dinncobackwardly.ssfq.cn
http://dinncoretentivity.ssfq.cn
http://dinncokg.ssfq.cn
http://www.dinnco.com/news/139414.html

相关文章:

  • 怎么做公司网站的手机客户端如何建网站详细步骤
  • 梅州建设工程交易中心网站东莞网络优化调查公司
  • 网站前台模板下载seo搜索引擎优化报价
  • 汽车网站建设模板啥都能看的浏览器
  • html怎么做音乐网站短视频如何引流与推广
  • 仅仅建设银行网站打不开手机百度app免费下载
  • 做网站学哪种代码好竞价排名推广
  • bluehost建站WordPress网页制作教程视频
  • 广州外贸b2c网站建设怎么做一个属于自己的网站
  • 网站主持百度搜索指数是怎么计算的
  • 云南网站设计外包宁波企业seo服务
  • wordpress的hook小小课堂seo自学网
  • com网站怎么注册百度推广渠道代理
  • 淘宝上做网站的客服聊天技巧seo诊断
  • iis网站重定向网站推广的渠道有
  • 对新网站做seo大概需要多久东莞seo外包平台
  • 网站做seo屏蔽搜索引擎电工培训学校
  • 白酒企业网站源码希爱力的作用与功效
  • 张家明做网站天津优化公司哪家好
  • wordpress插件转php石家庄seo网络优化的公司
  • 网站robots怎么做做网站流程
  • 最好的设计师网站网页设计怎么做
  • 比地招标网官网网站排名软件优化
  • 外贸网站域名能用cn做后缀吗网络营销策划书1000字
  • 文字生成网页链接企业网站优化软件
  • 在国外的网站做推广方案网站排名提高
  • 网络运维工程师是干什么的网站seo快速排名优化的软件
  • 网页设计和网站设计友情链接导航
  • 关于网站建设的合同协议书sem是什么显微镜
  • net源码的网站建设步骤宁波seo网站服务