|
楼主 |
发表于 2022-12-10 13:48
|
显示全部楼层
可以了,虽然没显示,网页数据还是在的,
强制循环所有"table" 虽然格式不一样:
- Sub CmBClick()
- Dim ie1 As Object, dmt As Object, r As Object, lr As Long, i As Long, j As Long, t As Long
- Dim Html As Object, XmlHttp As Object, url$, tb, n%
- Set Html = CreateObject("htmlfile")
- Set XmlHttp = CreateObject("MSXML2.XmlHttp")
- On Error Resume Next
- Application.DisplayAlerts = False
- Application.ScreenUpdating = False
- On Error Resume Next
- url = "https://www.lvdingjia.com/price/nanhai/"
- If url = "" Then Exit Sub
- With XmlHttp
- .Open "GET", url, False
- .Send
- Html.body.innerhtml = .ResponseText
- End With
- With ActiveSheet
- [a1].CurrentRegion.Clear
- Cells.NumberFormat = "@"
- For t = 0 To 9
- lr = .[A6536].End(xlUp).Row + 1
- Set tb = Html.all.tags("table")(t).Rows
- For i = 0 To tb.Length - 1
- For j = 0 To tb(i).Cells.Length - 1
- Cells(i + lr + 1, j + 1) = tb(i).Cells(j).innerText
- Next
- Next
- Next
- Application.ScreenUpdating = True
- Application.DisplayAlerts = True = False
- .[a1].CurrentRegion.Columns.AutoFit
- End With
- Set ie1 = Nothing
- Set dmt = Nothing
- Set r = Nothing
- End Sub
复制代码 |
|