- ©«¤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 ©ó 2022-7-9 16:40 ½s¿è
¦^´_ 1# smart3135
https://github.com/florentbr/SeleniumBasic/releases
¤U¸ü
SeleniumBasic-2.0.9.0.exe
§ó·schromeª©¥»
chrome>»¡©ú>Ãö©ógoogle chrome
¤â°Ê²Ä¤@¦¸§ó·schromedriverª©¥»
https://chromedriver.chromium.org/
¦ì¸mC:\Users\xxx\AppData\Local\SeleniumBasic\
¦w¸Ë¨Ã§ó·s«á ²Ä¤@¦¸´ú¸Õ
¶}©l>selenium Basic>Start Chome>¸õ¿ù>¦Û°Ê¦w¸Ë.net fromework>«¶}¾÷
²Ä¤G¦¸´ú¸Õ
¶}©l>selenium Basic>Start Chome>click ok to quit
«á´Á¤Þ¥Î¼gªk(ÁקK´«¹q¸£ÁÙn«³])
set driver = CreateObject("Selenium.ChromeDriver")
¾Þ§@¾Ç²ß°Ñ¦Òºô§}
https://club.excelhome.net/thread-1452021-1-1.html
¦Û°Ê§ó·schromedriver vba¥N½X(³q±`¤@Ӥ륪¥kgoogle·|§ó·sÂsÄý¾¹¤@¦¸)
Sub seleniumOPEN()
'§Q¥Îerror¤è¦¡§PÂ_selenium¬O§_²§±` Y¦³²§±`err´N¤£¬O0 ´N·|¶i¤J updataSelenium ªºµ{§Ç§ì¨ú·sªºchromedriveª©¥»
Do
On Error GoTo 0
On Error Resume Next
Set driver = CreateObject("Selenium.ChromeDriver")
Err = 0
driver.Get "https://www.google.com.tw" '¤@©wn¥[https:// ¤£µM·|¥X²{¯«©_ªº²§±`²{¶H
If Err <> 0 Then
driver.Quit
Set driver = Nothing
Call updataSelenium
End If
Loop Until Err = 0
msgbox "§¹¦¨"
End Sub
Sub updataSelenium()
'¥ý§PÂ_chromedriver¦bþÓ¸ê®Æ§¨
path1 = "C:\Users\" & Environ$("username") & "\AppData\Local\SeleniumBasic\Chromedriver.exe"
path2 = "C:\Program Files\SeleniumBasic\Chromedriver.exe"
If Dir(path1) <> "" Then TempDrvFile = path1
'Kill (TempDrvFile) '°²¦p¦b¿ù»~ªº±¡ªp¤U §ä¨ì¤FÀÉ®× ¨º¤§«á±Nn§ó·s½Æ»sÂл\ ÁקK¸õ¥X½Æ»s¤w¦s¦b¿ù»~ĵ§i ©Ò¥H¥ý§R°£±¼
If Dir(path2) <> "" Then TempDrvFile = path2
'§PÂ_chromeªºª©¥»¸¹
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)
'§PÂ_chromedriverª©¥»¸¹
Set oShell = CreateObject("wscript.shell")
errcode = oShell.Exec(path1 & " --version").StdOut.ReadAll
verarr = Split(errcode, " ")
chrdrv = verarr(1)
dotsarr2 = Split(chrdrv, ".")
leftchrdrv = dotsarr2(0) & dotsarr2(1)
If leftchrver = leftchrdrv Then Exit Sub '§Q¥Îª©¥»¸¹ªº«e¨â¦ì§PÂ_¬O§_¦Pª©¥»
'§Q¥Îª©¥»¸¹²Ä¤@¦ì ¤W©xºô¬d¸ß ·í«eª©¥»ªº³Ì²×ª©¥»¸¹
URL = "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_" & dotsarr(0)
Call objHttp.Open("GET", URL, False)
Call objHttp.Send("")
version_number = objHttp.responseText
dotsarr3 = Split(version_number, ".")
leftversion_no = dotsarr3(0) & dotsarr3(1)
download_url = "https://chromedriver.storage.googleapis.com/" + version_number + "/chromedriver_win32.zip"
'§Q¥Î¨ú±oªºª©¥»¸¹ ¨ú±o¤U¸üºô§} ¨Ã¶}±Òchromedriver.zip¤U¸ü¶±
Call objHttp.Open("GET", download_url, False)
Call objHttp.Send("")
'¶}±Òadodb±µ¦¬¤U¸üÀ£ÁYÀÉ ¨Ã©ñ¤Jseleniumªº¸ê®Æ§¨
Set fileStream = CreateObject("ADODB.Stream")
With fileStream
.Open
.Type = 1 'adTypeBinary
.Write objHttp.responseBody
.Position = 0
.SaveToFile "C:\Users\" & Environ$("username") & "\AppData\Local\SeleniumBasic\chromedriver.zip", 2 'adSaveCreateOverWrite 'adSaveCreateOverWrite
.Close
End With
'¸ÑÀ£ÁY ·|¥ý±Nª©ªº§R°£ ¤~¸ÑÀ£ÁY
Set oApp = CreateObject("Shell.Application")
If Dir(path1) <> "" Then Kill path1
oApp.Namespace("C:\Users\" & Environ$("username") & "\AppData\Local\SeleniumBasic\").CopyHere _
oApp.Namespace("C:\Users\" & Environ$("username") & "\AppData\Local\SeleniumBasic\chromedriver.zip").Items
'¥þ³¡§¹¦¨«á ·|¦^¨ì¤W¤@Ósub ¨Ã«·s§PÂ_¬O§_ª©¥»¿ù»~
End Sub |
|