返回列表 上一主題 發帖

[發問] Selenium

本帖最後由 singo1232001 於 2023-7-20 11:57 編輯

回復 1# t8899


如果你用xpath 就是這樣
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

本帖最後由 singo1232001 於 2023-7-20 11:05 編輯

回復 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 03:01 編輯

回復 1# t8899


<div class="Jc(fe) Mend(4px) Fw(600) D(f) Ai(c) C($c-trend-up)"   ' 這是紅色向上
<div class="Jc(fe) Mend(4px) Fw(600) D(f) Ai(c) C($c-trend-down)"  '這是綠色 向下


所以   
if  網頁元素物件.Attribute("class") Like "*C($c-trend-up)*" Then
debug.print "▲"  '正數
else
debug.print "▼"  '負數
end if


你也可以試著一個一個
debug.print  網頁元素物件.Attribute("class")  
觀察是不是你要的

TOP

        靜思自在 : 站在半路,比走到目標更辛苦。
返回列表 上一主題