VBA提取HTML文件信息

Sub test()
    Dim html As Object, D As Object, W As Object, arr()
    Set html = CreateObject("msxml2.xmlhttp")
    html.Open "GET", "file:///" & ThisWorkbook.Path & "内参平台.html", False
    html.send: strhtml = html.responseText
    Set D = CreateObject("htmlfile"): Set W = D.parentWindow
    D.write "<script src='http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js'></script><body></body>"
    D.body.innerHtml = strhtml
    W.execScript "a=[];$('div.time').each(function(){a.push($(this).text())});r=a.length;"
    W.execScript "b=[];$('div.time').siblings().filter('p').each(function(){b.push($(this).text())});c=b.length;"
    ReDim arr(1 To W.r, 1 To 2)
    For i = 0 To W.r - 1
        arr(i + 1, 1) = W.eval("a[" & i & "]")
        arr(i + 1, 2) = W.eval("b[" & i & "]")
    Next
    Cells.Clear
    [a:a].NumberFormatLocal = "h:mm;@"
    Range("a2").Resize(UBound(arr), 2) = arr
End Sub

原文地址:https://www.cnblogs.com/shida-liu/p/9396395.html