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

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

python 复制代码
''''对应表格复制
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
相关推荐
刘_sy7 小时前
使用EasyExcel和多线程实现高效数据导出
java·excel·easyexcel·批量导出excel
PowerBI学谦12 小时前
Copilot:Excel中的Python高级分析来了
python·excel·copilot
E-iceblue2 天前
Python 合并 Excel 单元格
python·excel·合并
sszdzq2 天前
Excel 合并列数据
excel
prince_zxill2 天前
Excel中不用复杂公式根据指定X列的数值N复制整行数据N行简单方法
excel
VBAMatrix3 天前
DeepSeek操作Excel,实现图表自动化生成
运维·自动化·excel·wps·deepseek
一醉千秋3 天前
excel中单元格字符串提取数字累加
excel
VB.Net3 天前
19.4.9 数据库方式操作Excel
数据库·c#·excel
真就死难3 天前
CSV格式和普通EXCEL格式文件的区别
linux·excel
朵朵zeng3 天前
Excel文件的读取
python·excel