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
posted on 2018-07-31 16:02 上山打老虎下山采蘑菇 阅读(1582) 评论(0) 编辑 收藏 举报