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作者: singo1232001 時間: 2023-7-20 11:55
Sub 時間內沒加載完就算失敗()
t = Timer '測試用可刪
Set driver = CreateObject("selenium.chromedriver")
driver.Timeouts.pageload = 10000 '要是秒數過低 沒加載完 就會強制關閉 可以試著測試3秒以下
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 '測試用可刪
End Sub
因為不曉得你的需求
所以我順便把重連三次的寫法也給你
Sub 重連三次每次等三秒_第四次就失敗()
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作者: t8899 時間: 2023-8-24 19:22
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作者: Scott090 時間: 2023-8-30 06:45