ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ¥ÎSelenium §ì¤W¥«¦æ±¡§Y®É¸ê®Æ ???

¦^´_ 50# singo1232001


    ·PÁ¤j¤j¥Î¤ß¦a¨ó§U¡C
    Google Chrome ±`±`¦b§ïª©¥»¹ê ¦b¬O®¹ÂZ¡A¥¦ªº ¶³ºÝµwºÐ ChromeDriveFs ¤]¬O¡C

TOP

¦^´_ 51# Scott090

¥Ñ©ó¦³¤H¤£ª¾¹D­n¥h¦w¸Ë¥D´¡¥ó ©Ò¥H¤]§â´¡¥ó¦w¸Ë¬yµ{¼g¶i¥h¤F
https://github.com/florentbr/SeleniumBasic/releases
SeleniumBasic v2.0.9.0.exe
²Ä¤@¦¸¦w¸Ë§¹¦¨«á,¥²¶·¦b¶}©l>°õ¦æselenium¤¤ªºstart chrome
µ¥«Ý¿ù»~¼u¥X¨Ã½T©w,±N¦Û°Ê¦w¸Ë.net framwork ¦w¸Ë§¹²¦«á­«¶}¾÷
¦A°õ¦æ¥»µ{§Ç«h¥i¥H§ó·sª©¥»


Sub updataSelenium()
'¥Ñ©óselenium¦³¥i¯à·|¦w¸Ë¦bwindows¤U¨â­Ó¨ä¤¤¤@­Ó¸ê®Æ§¨¤¤ ©Ò¥H­n¥ý§ä¥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 ¸ô®|
'­Y¥¼¦w¸Ëselenium 2.0.9.0 ±N·|¸õÂà¨ìgithubºô¯¸ ½Ð¦Û¦æ¤U¸ü¦w¸Ë
If foler = "" Then
    msg = "(½Ð©ç·Ó§ì¹Ï¥»µe­±)" & vbCrLf
    msg = msg & "§ä¤£¨ìselenium´¡¥ó¸ê®Æ§¨ »Ý¦Üºô¯¸" & vbCrLf & "https://github.com/florentbr/SeleniumBasic/releases"
    msg = msg & vbCrLf & "¤U¸ü¦w¸Ë SeleniumBasic v2.0.9.0.exe" & vbCrLf & vbCrLf & "¬O§_ª½±µ«e©¹?"
    msg = msg & vbCrLf & vbCrLf & "ª`·N«áÄò¨BÆJ:" & vbCrLf & "²Ä¤@¦¸¦w¸Ë§¹¦¨«á,¥²¶·¦b¶}©l>°õ¦æselenium¤¤ªºstart chrome" & vbCrLf
    msg = msg & "µ¥«Ý¿ù»~¼u¥X¨Ã½T©w,±N¦Û°Ê¦w¸Ë.net framwork ¦w¸Ë§¹²¦«á­«¶}¾÷" & vbCrLf & "¦A°õ¦æ¥»µ{§Ç«h¥i¥H§ó·sª©¥»"
    x = MsgBox(msg, vbYesNo, "¥¼¦w¸Ë´¡¥ó")
    If x = 6 Then
    edgePath1 = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
    edgePath2 = "C:\Program Files\Microsoft\Edge\Application\msedge.exe"
    If Dir(edgePath1) <> "" Then edgePath = edgePath1
    If Dir(edgePath2) <> "" Then edgePath = edgePath2
    edgePath = """" & edgePath & """" & " https://github.com/florentbr/SeleniumBasic/releases"
    Call Shell(edgePath, vbNormalFocus)
    End If
Exit Sub
End If

'Àò¨ú·í«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

TOP

¦^´_ 52# singo1232001

    ÁÂÁ¤j¤jªº²Ó¤ß»P¶K¤ß¡C
       SeleniumBasic ªºª©¥»¦n¤[¨S§ó·s¤F¡A ¤@ª½°±¯d¦b  v2.0.9.0¡C

    ´ú¸Õ¤F #52 ¼Óªºµ{¦¡¡A ½T¹ê¦¨¥\ªº§ó·s¨ì "Stable" ¤ºªº "116.0"ªºª©¥»¡C

TOP

¦^´_ 52# singo1232001

   ¦A½Ð±Ð ¤j¤j¡A ¤U¤@µ{¦¡¦p¦ó¶ñ¥[¥\¯à¨ú±o "¸ê®Æ®É¶¡ : 2023/08/21 10:44"¡A ÁÂÁÂ
  http://forum.twbts.com/viewthread.php?tid=23777&page=4
   Sub Test()
    Dim Driver As New Selenium.ChromeDriver
    Dim ID0 As Object, UL1
    Dim sp, u2%, ar(), i%, w%
    Dim sh As Worksheet
   
    Cells.ClearContents
   
    Set Driver = CreateObject("Selenium.ChromeDriver")
    If Driver Is Nothing Then opDriver
    Driver.AddArgument ("headless")     '¤£Åã¥ÜWebPage
'    Driver.Start
    Driver.Get "https://tw.stock.yahoo.com/quote/1101.TW"
   
    Set ID0 = Driver.FindElementByID("qsp-overview-realtime-info")
    Set UL1 = ID0.FindElementsByTag("ul")(1)
    '³æ¦C
    sp = Split(UL1.text, Chr(10))
    Cells(1, 1).Resize(UBound(sp) + 1, 1) = Application.Transpose(sp)
   
    'Âù¦C
    u2 = UBound(sp) / 2
    ReDim ar(1 To u2, 1 To 2)
    For i = 0 To UBound(sp) Step 2
        w = w + 1
        ar(w, 1) = sp(i)
        ar(w, 2) = sp(i + 1)
    Next
    Cells(1, 3).Resize(UBound(ar), 2) = ar
End Sub

TOP

Driver.Get "https://tw.stock.yahoo.com/quote/1101.TW"

   Do: Set ID0 = Driver.findelementsbyID("main-0-QuoteHeader-Proxy")
        If ID0.Count > 0 Then Exit Do
        Loop
   Do: Set spans = ID0(1).findelementsbytag("span")
        If spans.Count > 0 Then Exit Do
        Loop
    For Each Z In spans
    If Z.Text Like "*¶}½L*§ó·s*" Then
    ®É¶¡ = Replace(Z.Text, "¶}½L | ", "")
    ®É¶¡ = "¸ê®Æ®É¶¡:" & Replace(®É¶¡, " §ó·s", "")
    Exit For
    End If
    Next

TOP

¦^´_ 55# singo1232001

  ¸g´ú¸Õ«á¡A ®É¶¡ÅܼƬOªÅ¥Õ¡A ¤£ª¾°ÝÃD¦b­þ¸Ì
  ½Ð ¤j¤j ¦A¬Ý¬Ý
  ÁÂÁÂ

TOP

¦^´_ 56# Scott090

Driver.Get "https://tw.stock.yahoo.com/quote/1101.TW"

   Do: Set ID0 = Driver.findelementsbyID("main-0-QuoteHeader-Proxy")
        If ID0.Count > 0 Then Exit Do
        Loop
   Do: Set spans = ID0(1).findelementsbytag("span")
        If spans.Count > 0 Then Exit Do
        Loop
    For Each Z In spans
    If Z.Text Like "*½L*§ó·s*" Then
    sp = Split(Z.Text, " ")
    ®É¶¡ = "¸ê®Æ®É¶¡:" & sp(2) & " " & sp(3)
    Exit For
    End If
    Next

TOP

¦^´_ 57# singo1232001


    ¦³±o¨ì¥¿½Tªº¸ê®Æ¤F¡G
         ®É¶¡ =  "¸ê®Æ®É¶¡:2023/08/21 14:30"

    «D±`·P®¦

TOP

¦^´_ 52# singo1232001
path1 = "C:\Users\" & Environ$("username") & "\AppData\Local\SeleniumBasic\Chromedriver.exe"
1.§Ú¬O¸Ë¦b¤W­±ªº¸ê®Æ§¨?¨S§ì¨ì?§Ú´N§â"C:\Users\" & Environ$("username") & "ª½±µ´«¦¨¹ê»Úªº¸ô®|¤~§ì¨ì ?
2.¤U¸ü¦³¦¨¥\, ¤]¦³¸ÑÀ£ÁY¡A¦ýzipÀɨS§R°£ ?

TOP

¦^´_ 59# t8899


    1. ¥i¥H  ©ÎªÌ¦Û¤v³]­ÓPATH3 ,¦ADIR °µ§PÂ_
2.­Y¤£¼vÅT  ¨º´N©ñµÛ¤£ºÞ¥L´N¦n À³¸Ó¬O§Ú¨S¼g§R°£ZIPªº¥\¯à

TOP

        ÀR«ä¦Û¦b : ·O´d¨S¦³¼Ä¤H¡A´¼¼z¤£°_·Ð´o¡C
ªð¦^¦Cªí ¤W¤@¥DÃD