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
相关推荐
CodeCraft Studio12 分钟前
Excel处理控件Aspose.Cells教程:使用 Python 将 HTML 转换为 Excel
python·html·excel·aspose·aspose.cells·html转excel
Leo6553516 分钟前
Excel 读取阶段就去掉换行
excel
小镇学者1 小时前
【PHP】利用 xlswriter 扩展导出的Excel文件报错问题
php·excel
程序员杰哥2 小时前
Pytest与Unittest测试框架对比
自动化测试·软件测试·python·测试工具·测试用例·excel·pytest
cehuishi95273 小时前
excel中关联word邮件合并使用
word·excel·批量打印·邮件合并
曾令胜10 小时前
excel导出使用arthas动态追踪方法调用耗时后性能优化的过程
spring·性能优化·excel
我命由我1234513 小时前
Excel - Excel 列出一列中所有不重复数据
经验分享·学习·职场和发展·word·powerpoint·excel·职场发展
Lucky GGBond16 小时前
Vue + Spring Boot 实现 Excel 导出实例
vue.js·spring boot·excel
缺点内向1 天前
C# 中 Excel 工作表打印前页面边距的设置方法
c#·.net·excel
极智-9961 天前
Excel如何合并单元格?【图文详解】Excel合并单元格技巧?单元格合并高阶操作?
excel·excel如何合并单元格·excel合并单元格技巧·单元格合并高阶操作·单元格合并·取消单元格合并·重复数据合并