EXCEL VBA网抓技巧-复制网页表格,不用遍历单元格
''''对应表格复制
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
文章来源地址https://www.toymoban.com/news/detail-823737.html
文章来源:https://www.toymoban.com/news/detail-823737.html
到了这里,关于EXCEL VBA网抓技巧-复制网页表格,不用遍历单元格的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!