# as per https://stackoverflow.com/questions/580924/python-windows-file-version-attribute
import win32api
#==============================================================================
def getFileProperties(fname):
#==============================================================================
"""
Read all properties of the given file return them as a dictionary.
"""
propNames = ('Comments', 'InternalName', 'ProductName',
'CompanyName', 'LegalCopyright', 'ProductVersion',
'FileDescription', 'LegalTrademarks', 'PrivateBuild',
'FileVersion', 'OriginalFilename', 'SpecialBuild')
props = {'FixedFileInfo': None, 'StringFileInfo': None, 'FileVersion': None}
try:
# backslash as parm returns dictionary of numeric info corresponding to VS_FIXEDFILEINFO struc
fixedInfo = win32api.GetFileVersionInfo(fname, '\\')
props['FixedFileInfo'] = fixedInfo
props['FileVersion'] = "%d.%d.%d.%d" % (fixedInfo['FileVersionMS'] / 65536,
fixedInfo['FileVersionMS'] % 65536, fixedInfo['FileVersionLS'] / 65536,
fixedInfo['FileVersionLS'] % 65536)
# \VarFileInfo\Translation returns list of available (language, codepage)
# pairs that can be used to retreive string info. We are using only the first pair.
lang, codepage = win32api.GetFileVersionInfo(fname, '\\VarFileInfo\\Translation')[0]
# any other must be of the form \StringfileInfo\%04X%04X\parm_name, middle
# two are language/codepage pair returned from above
strInfo = {}
for propName in propNames:
strInfoPath = u'\\StringFileInfo\\%04X%04X\\%s' % (lang, codepage, propName)
## print str_info
strInfo[propName] = win32api.GetFileVersionInfo(fname, strInfoPath)
props['StringFileInfo'] = strInfo
except:
pass
return props
在镀铬.py在
^{pr2}$
中华人民共和国romeDriverAutomation.py在
from ChromeVersion import chrome_browser_version, nextVersion, lastVersion
driverName = "\\chromedriver.exe"
# defining base file directory of chrome drivers
driver_loc = #"C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37-32\\ChromeDriver\\" ENTER the file path of your exe
# I created a separate folder to house the versions of chromedriver, previous versions will be deleted after downloading the newest version.
# ie. version 75 will be deleted after 77 has been downloaded.
# defining the file path of your exe file automatically updating based on your browsers current version of chrome.
currentPath = driver_loc + chrome_browser_version + driverName
# check file directories to see if chrome drivers exist in nextVersion
import os.path
# check if new version of drive exists > only continue if it doesn't
Newpath = driver_loc + nextVersion
# check if we have already downloaded the newest version of the browser, ie if we have version 76, and have already downloaded a version of 77, we don't need to run any more of the script.
newfileloc = Newpath + driverName
exists = os.path.exists(newfileloc)
if (exists == False):
#open chrome driver and attempt to download new chrome driver exe file.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time
chrome_options = Options()
executable_path = currentPath
driver = webdriver.Chrome(executable_path=executable_path, options=chrome_options)
# opening up url of chromedriver to get new version of chromedriver.
chromeDriverURL = 'https://chromedriver.storage.googleapis.com/index.html?path=' + nextVersion
driver.get(chromeDriverURL)
time.sleep(5)
# find records of table rows
table = driver.find_elements_by_css_selector('tr')
# check the length of the table
Table_len = len(table)
# ensure that table length is greater than 4, else fail. table length of 4 is default when there are no availble updates
if (Table_len > 4 ):
# define string value of link
rowText = table[(len(table)-2)].text[:6]
time.sleep(1)
# select the value of the row
driver.find_element_by_xpath('//*[contains(text(),' + '"' + str(rowText) + '"'+')]').click()
time.sleep(1)
#select chromedriver zip for windows
driver.find_element_by_xpath('//*[contains(text(),' + '"' + "win32" + '"'+')]').click()
time.sleep(3)
driver.quit()
from zipfile import ZipFile
import shutil
fileName = #r"C:\Users\Administrator\Downloads\chromedriver_win32.zip" > enter your download path here.
# Create a ZipFile Object and load sample.zip in it
with ZipFile(fileName, 'r') as zipObj:
# Extract all the contents of zip file in different directory
zipObj.extractall(Newpath)
# delete downloaded file
os.remove(fileName)
# defining old chrome driver location
oldPath = driver_loc + lastVersion
oldpathexists = os.path.exists(oldPath)
# this deletes the old folder with the older version of chromedriver in it (version 75, once 77 has been downloaded)
if(oldpathexists == True):
shutil.rmtree(oldPath, ignore_errors=True)
exit()
没有,除了更新ChromeDriver二进制版本之外,没有其他选择,而Chrome浏览器会不断自动更新。在
原因
每个Chrome浏览器都是在对现有功能进行某些添加、修改和删除后发布的。为了符合当前浏览器的一系列功能,Chrome团队将适时发布兼容的ChromeDriver二进制文件。这些ChromeDriver二进制文件能够与Chrome浏览器进行交互。ChromeDriver二进制文件的某些版本支持特定范围的Chrome Browser版本(一些最新版本),如下所示:
铬驱动v80.0.3987.16(2019-12-19)
<36.39英里/小时
铬驱动v78.0.3904.70(2019-10-21)
铬驱动v77.0.3865.40(2019-08-20)
铬驱动v76.0.3809.126(2019-08-20)
铬驱动v75.0.3770.8(2019-04-29)
<14.03>
铬驱动v73.0.3683.68(2019-03-06)
铬驱动v2.46(2019-02-01)
ChromeDriver v2.45(2018-12-10)
ChromeDriver v2.44(2018-11-19)
ChromeDriver v2.43(2018-10-16)
ChromeDriver v2.42(2018-09-13)
铬驱动v2.41(2018-07-27)
ChromeDriver v2.40(2018-06-07)
ChromeDriver v2.39(2018-05-30)
ChromeDriver v2.38(2018-04-17)
ChromeDriver v2.37(2018-03-16)
ChromeDriver v2.36(2018-03-02)
ChromeDriver v2.35(2018-01-10)
ChromeDriver v2.34(2017-12-10)
ChromeDriver v2.33(2017-10-03)
ChromeDriver v2.32(2017-08-30)
ChromeDriver v2.31(2017-07-21)
ChromeDriver v2.30(2017-06-07)
ChromeDriver v2.29(2017-04-04)
结论
要使脚本/程序与更新的Chrome浏览器保持交互,必须根据兼容性使ChromeDriver二进制版本与Chrome浏览器保持同步。在
这就是我构建的(也使用了另一个stackoverflow线程的一些预写代码),它可以为您工作。我每次都将脚本设置为从全局驱动程序脚本运行,以确保它使用正确的ChromeDriver.exe文件。在
但是在遇到此问题之前,您需要首先确保您正在安装新的驱动程序,这些脚本将自动下载最新版本/查找ChromeDriver的最新版本并将其下载到新的文件夹位置。只有当你的Chrome版本更新后,它才会使用新的文件夹位置。如果浏览器版本的chrome更新,并且在上没有可用版本,脚本应该会正常失败chromedriver.storage.谷歌皮斯.com。在
我在我的操作系统路径中设置了四个脚本,以便可以全局访问我的驱动程序。下面是我用来更新浏览器的脚本。在
希望这有道理。在
干杯! 马特
在获取文件属性.py在
在镀铬.py在
^{pr2}$中华人民共和国romeDriverAutomation.py在
https://github.com/MattWaller/ChromeDriverAutoUpdate
相关问题 更多 >
编程相关推荐