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

[µo°Ý] Selenium

[µo°Ý] Selenium



½Ð±Ð§Ú­n§ì¹Ï¤¤ªººñ¦â³¡¥÷(§t­Ë¤T¨¤§Î),«ç»ò§ì(»yªk)?
https://tw.stock.yahoo.com/quote/2330
±qºô­¶±oª¾FindElementByXPath
//*[@id="qsp-overview-realtime-info"]/div[2]/div[2]/div/ul/li[8]/span[2]
³o¬O­Ë¤T¨¤§Î§t¼Æ¦r
//*[@id="qsp-overview-realtime-info"]/div[2]/div[2]/div/ul/li[8]/span[2]/span
³o¥u¦³­Ë¤T¨¤§Î

¥»©«³Ì«á¥Ñ singo1232001 ©ó 2023-7-20 03:01 ½s¿è

¦^´_ 1# t8899


<div class="Jc(fe) Mend(4px) Fw(600) D(f) Ai(c) C($c-trend-up)"   ' ³o¬O¬õ¦â¦V¤W
<div class="Jc(fe) Mend(4px) Fw(600) D(f) Ai(c) C($c-trend-down)"  '³o¬Oºñ¦â ¦V¤U


©Ò¥H   
if  ºô­¶¤¸¯Àª«¥ó.Attribute("class") Like "*C($c-trend-up)*" Then
debug.print "¡¶"  '¥¿¼Æ
else
debug.print "¡¿"  '­t¼Æ
end if


§A¤]¥i¥H¸ÕµÛ¤@­Ó¤@­Ó
debug.print  ºô­¶¤¸¯Àª«¥ó.Attribute("class")  
Æ[¹î¬O¤£¬O§A­nªº

TOP

¥»©«³Ì«á¥Ñ singo1232001 ©ó 2023-7-20 11:05 ½s¿è

¦^´_ 1# t8899


Sub ttt()
Set driver = CreateObject("Selenium.ChromeDriver")
driver.get "https://tw.stock.yahoo.com/quote/2330"
driver.Wait 1000
Set ID_0 = driver.findelementbyID("qsp-overview-realtime-info")
Set ID_0_ul_S = ID_0.findelementsbytag("ul")
Set ID_0_ul_S_1_li_S = ID_0_ul_S(1).findelementsbytag("li")

For i = 1 To ID_0_ul_S_1_li_S.Count
Set x = ID_0_ul_S_1_li_S(i).findelementsbytag("span")
  If x(1).Text Like "*º¦¶^*" Then

      Select Case True
      Case x(2).Attribute("class") Like "*C($c-trend-up)*": tx = "¡¶ " & x(2).Text
      Case x(2).Attribute("class") Like "*C($c-trend-down)*": tx = "¡¿ " & x(2).Text
      Case Else: tx = x(2).Text
      End Select
  
      Debug.Print x(1).Text & " " & tx
  Else
      Debug.Print x(1).Text & " " & x(2).Text
  End If
Next
Stop
End Sub

TOP

¥»©«³Ì«á¥Ñ singo1232001 ©ó 2023-7-20 11:57 ½s¿è

¦^´_ 1# t8899


¦pªG§A¥Îxpath ´N¬O³o¼Ë
Sub tttt()
Set driver = CreateObject("Selenium.ChromeDriver")
driver.get "https://tw.stock.yahoo.com/quote/2330"
driver.Wait 1000

Set xp = driver.findelementbyxpath("//*[@id=""qsp-overview-realtime-info""]/div[2]/div[2]/div/ul/li[8]")
      Set sn = xp.findelementsbytag("span")

Select Case True
Case sn(2).Attribute("class") Like "*C($c-trend-up)*": tx = "¡¶ "
Case sn(2).Attribute("class") Like "*C($c-trend-down)*": tx = "¡¿ "
Case Else: tx = " - "
End Select
Debug.Print sn(1).Text & " " & tx & " " & sn(2).Text
  
Stop
End Sub

TOP

¦^´_ 4# singo1232001

ÁÂÁ«ü¾É

TOP

¦^´_ 4# singo1232001

drIVER.get "https://finance.yahoo.com/quote/TSM/"
½Ð±Ð¦pªG³s½u¶W¹L3¬í¦³°ÝÃD?«h¸õ¥Xªº»yªk?

TOP

¥»©«³Ì«á¥Ñ singo1232001 ©ó 2023-8-24 18:13 ½s¿è

¦^´_ 6# t8899


Sub ®É¶¡¤º¨S¥[¸ü§¹´Nºâ¥¢±Ñ()
t = Timer '´ú¸Õ¥Î¥i§R
Set driver = CreateObject("selenium.chromedriver")
driver.Timeouts.pageload = 10000 '­n¬O¬í¼Æ¹L§C ¨S¥[¸ü§¹ ´N·|±j¨îÃö³¬ ¥i¥H¸ÕµÛ´ú¸Õ3¬í¥H¤U
On Error Resume Next
driver.get "https://finance.yahoo.com/quote/TSM/"
If Err.Number <> 0 Then
Err.Clear
driver.Quit
End If
On Error GoTo 0
Debug.Print Timer - t  '´ú¸Õ¥Î¥i§R
End Sub




¦]¬°¤£¾å±o§Aªº»Ý¨D
©Ò¥H§Ú¶¶«K§â­«³s¤T¦¸ªº¼gªk¤]µ¹§A

Sub ­«³s¤T¦¸¨C¦¸µ¥¤T¬í_²Ä¥|¦¸´N¥¢±Ñ()
Set driver = CreateObject("selenium.chromedriver")
On Error Resume Next
Do
driver.Get "https://finance.yahoo.com111111111/quote/TSM/"
If Err.Number <> 0 Then
    Err.Clear
    Application.Wait Now + TimeValue("00:00:03")
    rT = rT + 1
    If rT = 3 Then driver.Quit: Exit Do
Else
    Exit Do
End If
Loop
On Error GoTo 0
End Sub

TOP

¦^´_ 7# singo1232001

ÁÂÁ«ü¾É

TOP

¦^´_ 8# t8899

    ½Ð°Ý¦p¦ó¦b¦¹ºô­¶ "https://finance.yahoo.com/quote/TSM/"
        ¨ú±o¤U¦C³o¤@¨Ç¸ê®Æ ?  
    ÁÂÁÂ

   Previous Close        549.00
Open        551.00
Bid        552.00 x 0
Ask        553.00 x 0
Day's Range        546.00 - 553.00
52 Week Range        370.00 - 594.00
Volume        10,650,708
Avg. Volume        22,277,577

TOP

¦^´_ 9# Scott090


    Sub test()
Set driver = CreateObject("selenium.chromedriver")
driver.get "https://finance.yahoo.com/quote/TSM/"

Do: Set ids = driver.findelementsbyId("quote-summary")
    If ids.Count > 0 Then Exit Do
    Loop
Do: Set tby = ids(1).findelementsbytag("tbody")
    If tby.Count > 0 Then Exit Do
    Loop
   
Debug.Print tby(1).Text


Set trs = tby(1).findelementsbytag("tr")
ReDim ar(1 To trs.Count, 1)
For i = 1 To trs.Count
    Set tds = trs(i).findelementsbytag("td")
    ar(i, 0) = tds(1).Text
    ar(i, 1) = tds(2).Text
Next

Cells.ClearContents
Range("a1").Resize(UBound(ar), 2) = ar
End Sub

TOP

        ÀR«ä¦Û¦b : Ãø¦æ¯à¦æ¡AÃø±Ë¯à±Ë¡AÃø¬°¯à¬°¡A¤~¯àª@µØ¦Û§Úªº¤H®æ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD