返回列表 上一主題 發帖

[發問] 請教這網頁附圖表格是在第幾???(table)

請教這網頁要直接匯入工作表要如何改??

https://tw.stock.yahoo.com/d/i/rank.php?t=up&e=tse
Sub test()
    Set Ie = CreateObject("InternetExplorer.Application")
    Ie.Visible = True
       Ie.Navigate "https://tw.stock.yahoo.com/d/i/rank.php?t=up&e=tse"
Do While Ie.Busy Or Ie.ReadyState <> 4: DoEvents: Loop

    Dim I As Integer, S As Integer, k As Integer, J As Integer
     Dim Element
    Set Element = Ie.document.getelementsbytagname("table")
    With Sheets("sheet2")
      .Range("a1:f30").ClearContents
        For S = 2 To 2                    '已找出網頁的table內容在 2 中
            For I = 0 To Element(S).Rows.Length - 1
                k = k + 1
                For J = 0 To Element(S).Rows(I).Cells.Length - 1   '資料的欄位共6位
                .Cells(k, J + 1) = Element(S).Rows(I).Cells(J).innerText
                Next
            Next
        Next

    End With
    Set Element = Nothing
               
Ie.Quit
End Sub

TOP

已解決...........

TOP

[發問] 請教這網頁附圖表格是在第幾???(table)

https://pchome.megatime.com.tw/rank/sto0/ock03.html

請教這網頁附圖表格是在第幾???(table)

回復  t8899
GBKEE 發表於 2020-5-10 15:13


又學習到新的抓法, 謝謝指導!

TOP

        靜思自在 : 自己害自己,莫過於亂發脾氣。
返回列表 上一主題