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
相关推荐
cspttty18 小时前
2027采购岗求职:大数据管理与应用专业如何把Excel、SQL变成业务能力
excel
ms365copilot20 小时前
Excel Copilot 一键定位修改的内容
excel·copilot
帆张芳显2 天前
前端表格公式能力新选择|智表 ZCell 公式引擎深度剖析
前端·excel·canva可画·excel插件
地图小课堂2 天前
Bigemap Pro 导入 Excel、CSV、TXT 点位表格教程
excel
我的愿望是成为富婆2 天前
2027校招准备:从Excel操作到数据分析,还缺业务、SQL与统计思维
sql·数据分析·excel
用户0332126663673 天前
Python 自动化办公:如何从零快速生成结构清晰的 Excel 报表
python·excel
千桐科技3 天前
qData 数据中台专业版功能解析:告别 Excel 与 SQL 拼凑,打通系统合并的可追踪数据链路
数据库·sql·excel·qdata
百事牛科技3 天前
从局部到整体:Excel限制功能的几种实用设置
windows·excel
ProcessOn官方账号3 天前
ProcessOn Office 插件上线:在 Word / Excel / PPT 里直接画流程图
word·excel·插件·office·processon
reasonsummer4 天前
【办公类-53-12】20261016(预测)Python模仿制作2026学年第二学期校历(excel+pdf,上下学期都包含)
pdf·excel