EXCEL VBA网抓技巧-复制网页表格,不用遍历单元格

''''对应表格复制
Sub tableTest()
    Set winhttp = CreateObject("winhttp.WinHttpRequest.5.1")
    Set HTML = CreateObject("htmlfile")
    Set oWindow = HTML.ParentWindow
    Url = "https://www.taiwanlottery.com.tw/Lotto/BINGOBINGO/drawing.aspx"
    With winhttp
        .Open "GET", Url, False
        .send
        strText = .responsetext
''            Debug.Print strText
    End With
    HTML.body.innerhtml = strText
    Set tables = HTML.getElementsByClassName("tableFull")
    Set Table = tables(0)
    
    '''写入剪切板 第一种
    oWindow.ClipboardData.SetData "text", Table.outerHTML
    
    '''写入剪切板 第二种
'    Set clipboard = New MSForms.DataObject
'    clipboard.SetText Table.outerHTML
'    clipboard.PutInClipboard

    ActiveSheet.Range("a1").Select
    ActiveSheet.Paste
    
    Set winhttp = Nothing
    Set HTML = Nothing
    Set oWindow = Nothing
End Sub
''''所有表格
Sub alltableTest()
    Set winhttp = CreateObject("winhttp.WinHttpRequest.5.1")
    Set HTML = CreateObject("htmlfile")
    Set oWindow = HTML.ParentWindow
    Url = "https://www.taiwanlottery.com.tw/Lotto/BINGOBINGO/drawing.aspx"
    With winhttp
        .Open "GET", Url, False
        .send
        strText = .responsetext
''            Debug.Print strText
    End With
    HTML.body.innerhtml = strText
    Set tables = HTML.getElementsByTagName("table")
    aa = 1
    For i = 0 To tables.Length - 1
        Set Table = tables(i)
        
        '''写入剪切板 第一种
        oWindow.ClipboardData.SetData "text", Table.outerHTML
        
        '''写入剪切板 第二种
    '    Set clipboard = New MSForms.DataObject
    '    clipboard.SetText Table.outerHTML
    '    clipboard.PutInClipboard
    
        ActiveSheet.Cells(1, aa).Select
        ActiveSheet.Paste
        oWindow.ClipboardData.SetData "text", ""
        aa = ActiveSheet.UsedRange.Columns.Count + 2
    Next
    Set winhttp = Nothing
    Set HTML = Nothing
    Set oWindow = Nothing
End Sub

01-25 10:03