- ©«¤l
- 354
- ¥DÃD
- 5
- ºëµØ
- 0
- ¿n¤À
- 387
- ÂI¦W
- 0
- §@·~¨t²Î
- windows7
- ³nÅ骩¥»
- vba,vb,excel2007
- ¾\ŪÅv
- 20
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2017-1-8
- ³Ì«áµn¿ý
- 2024-8-2
|
¥»©«³Ì«á¥Ñ singo1232001 ©ó 2023-8-20 19:47 ½s¿è
¦^´_ 49# Scott090
¥»¤H¤£¬O«Ü±M·~ ¦Û¤v¤]¨S§â´¤¥i¥H100%¨S°ÝÃD
¥[¤W¤£ª¾¹D¤§«á¦³¨º¨Çºô§}»P»yªk¬O©T©wªº
©Ò¥H¥i¥H¥ý±N´N¥Î¬Ý¬Ý
Sub updataSelenium()
'¥Ñ©óselenium¦³¥i¯à·|¦w¸Ë¦bwindows¤U¨âӨ䤤¤@Ó¸ê®Æ§¨¤¤ ©Ò¥Hn¥ý§ä¥X¸ê®Æ§¨¦ì¸m (mac¥Ø«e¥¼¦Ò¼{)
path1 = "C:\Users\" & Environ$("username") & "\AppData\Local\SeleniumBasic\Chromedriver.exe"
path2 = "C:\Program Files\SeleniumBasic\chromedriver.exe"
If Dir(path1) <> "" Then TempDrvFile = path1
If Dir(path2) <> "" Then TempDrvFile = path2
foler = Left(TempDrvFile, InStrRev(TempDrvFile, "\")) '¨ú±o ¸ê®Æ§¨¸ô®| »P chromedrive.exe ¸ô®|
'Àò¨ú·í«echromedriverª©¥»«e¨â½X ¨Ò: 117.0
Set oShell = CreateObject("wscript.shell")
errcode = oShell.Exec(TempDrvFile & " --version").StdOut.ReadAll
verarr = Split(errcode, " ")
chrdrv = verarr(1)
dotsarr2 = Split(chrdrv, ".")
'Àò¨úchrome·í«eÂsÄý¾¹ª©¥»¸¹ ¨Ò: 117.0
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0") 'Get chrome version
chrversion = CreateObject("WScript.Shell").RegRead("HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon\version")
dotsarr = Split(chrversion, ".")
leftchrver = dotsarr(0) & dotsarr(1)
'¤ñ¹ïchromedriver »P chromeÂsÄý¾¹ ¨âÓª©¥»¸¹, ¬Û¦P(¤£§ó·s) ; ¤£¦P(¤W©xºô¬dÂsÄý¾¹³Ì·sª©¥»¸¹ ¨ÃÄ~Äò¤U¸ü¸ÑÀ£¨ú¥N)
leftchrdrv = dotsarr2(0) & dotsarr2(1)
If leftchrver = leftchrdrv Then Exit Sub
'¨ì©xºôapiÀò¨úª©¥»¸ê°T ¨Ã©î¸Ñ¸ê°T ¸Ó¸ê°T¬°json®æ¦¡ ¨ÃÀò±o·í«eÂsÄý¾¹¥i¥Îªºchromedriverª©¥»¸¹
'¥»json©îªk¬°¯S»s ¤£²Å¦X¥¿³Wjson ¤£ª¾¹D¥¼¨Óªº®æ¦¡·|¤£·|ÅÜ ¦]¬°¤£·Q¤Þ¥ÎÃB¥~ª«¥ó
Url = "https://googlechromelabs.github.io/chrome-for-testing/latest-versions-per-milestone.json"
Call objHTTP.Open("GET", Url, False)
Call objHTTP.Send("")
version_number = objHTTP.responseText
v0 = Split(version_number, ",""milestones"":{")
v1 = Split(v0(1), "},")
For i = 0 To UBound(v1)
v1(i) = Replace(v1(i), """", "")
v1(i) = Replace(v1(i), ":{milestone:", ",")
v1(i) = Replace(v1(i), ",version:", ",")
v1(i) = Replace(v1(i), ",revision:", ",")
v1(i) = Replace(v1(i), "}}}", ",")
Next
ReDim v2(UBound(v1))
For i = 0 To UBound(v1): v2(i) = Split(v1(i), ","): Next
For i = 0 To UBound(v2)
If v2(i)(0) = dotsarr(0) Then: version_number = v2(i)(2): Exit For
Next
'¥Í¦¨³sµ²ºô§} (¥t¶·ª`·N¿ï¾Ü§@·~¨t²Î¦ì¤¸ ¦b¤U¤ècmd³B ¤]¦³»Ýnק諸³¡¤À) ¤£ª¾¹D¥¼¨Óºô§}·|¤£·|ÅÜ
'download_url = "https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/" & version_number & "/linux64/chromedriver-linux64.zip"
'download_url = "https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/" & version_number & "/mac-x64/chromedriver-mac-x64.zip"
'download_url = "https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/" & version_number & "/win32/chromedriver-win32.zip"
download_url = "https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/" & version_number & "/win64/chromedriver-win64.zip"
Call objHTTP.Open("GET", download_url, False)
Call objHTTP.Send("")
Set fileStream = CreateObject("ADODB.Stream") '¨Ï¥Îadodb.stream ±µ¨üÀÉ®×
With fileStream
.Open
.Type = 1 'adTypeBinary
.Write objHTTP.responseBody
.Position = 0
.SaveToFile foler & "chromedriver.zip", 2 ' ¤U¸üÀɮרìselenium¸ê®Æ§¨ ' 2 adSaveCreateOverWrite
.Close
End With
'¨Ï¥Îshell+cmd±þªºÀÉ®× killªº¤è¦¡³Q·L³n«Ê¤F
Set oApp = CreateObject("Shell.Application")
cmdCommand = "cmd /c del " & foler & "chromedriver.exe" '¨Ï¥Îcmd§R°£ÀÉ®× cmd /c del "path"
Call Shell(cmdCommand, vbHide) '±þ±¼Âªºchromedriver.exe
cmdCommand = "cmd /c del " & foler & "LICENSE.chromedriver"
Call Shell(cmdCommand, vbHide) '±þ±¼ÂªºLICENSE.chromedriver
'Y¨S±þ¦¨¥\ ¸Óµ{§Ç¨SÃö³¬ µLªk§R°£®É ±N°õ¦æ¦î¦C¤¤ªºÀÉ®×Ãö³¬ 'cmd /c taskkill /F /IM chromedriver.exe ¬O±þ¦î¦C
If Dir(foler & "chromedriver.exe") <> "" Then
cmdCommand = "cmd /c taskkill /F /IM chromedriver.exe && cmd /c del " & foler & "chromedriver.exe" '±þ±¼Âªºchromedriver.exe
Call Shell(cmdCommand, vbHide)
End If
If Dir(foler & "LICENSE.chromedriver") <> "" Then
cmdCommand = "cmd /c taskkill /F /IM LICENSE.chromedriver && cmd /c del " & foler & "LICENSE.chromedriver" '±þ±¼ÂªºLICENSE.chromedriver
Call Shell(cmdCommand, vbHide)
End If
'±N·sªºchromedriver.exe¸ÑÀ£ÁY¨ì¸ê®Æ§¨¤¤ 16¬O±j¨î¨ú¥N¿ï¶µ ª`·NÀ£ÁYÀɤºªºÀɦW ·|¦]¨t²Î¦ì¤¸¤£¦P¸ê®Æ§¨¤£¦P
oApp.Namespace(foler).CopyHere _
oApp.Namespace(foler & "chromedriver.zip\chromedriver-win64").items, 16
End Sub |
|