所以我對這里列出的問題有完全相同的問題
在那個問題中,問題在于 ChromeDriver 是 99 版,但 Chrome 是 98 版。接受的答案表明 Chrome 驅動程式適用于“尚未發布”的 Chrome 版本。我目前正在使用此代碼獲取最新版本的 ChromeDriver
# get the latest chrome driver version number
chrome_url = 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE'
response = requests.get(chrome_url)
version_number = response.text
# build the donwload url
download_url = "https://chromedriver.storage.googleapis.com/" version_number "/chromedriver_win32.zip"
有沒有辦法用回傳當前版本的chrome的東西替換代碼中的第一部分?
uj5u.com熱心網友回復:
我找到了一種讓它作業的方法,可能不是最好的方法,但它確實有效。
def get_version_via_com(filename):
parser = Dispatch("Scripting.FileSystemObject")
try:
v = parser.GetFileVersion(filename)
except Exception:
return None
return v
if __name__ == "__main__":
# Get Version of Chrome
paths = [r"C:\Program Files\Google\Chrome\Application\chrome.exe",
r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"]
version = list(filter(None, [get_version_via_com(p) for p in paths]))[0]
# build the donwload url
download_url = "https://chromedriver.storage.googleapis.com/" version "/chromedriver_win32.zip"
# download the zip file using the url built above
latest_driver_zip = wget.download(download_url, 'chromedriver.zip')
# extract the zip file
with zipfile.ZipFile(latest_driver_zip, 'r') as zip_ref:
zip_ref.extractall() # you can specify the destination folder path here
# delete the zip file downloaded above
os.remove(latest_driver_zip)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/440227.html
