我正在尝试从网页上获取表格,但没有结果,而且我没有收到任何错误消息。下面是我试过的代码。
Sub Web_Table_Option_One()
Dim xml As Object
Dim html As Object
Dim objTable As Object
Dim result As String
Dim lRow As Long
Dim lngTable As Long
Dim lngRow As Long
Dim lngCol As Long
Dim ActRw As Long
Set xml = CreateObject("MSXML2.XMLHTTP.6.0")
With xml
.Open "GET", "https://www.99acres.com/microsite/ambey-group-eco-valley-new-town-kolkata-east/", False
.Send
End With
result = xml.responseText
Set html = CreateObject("htmlfile")
html.body.innerHTML = result
Set objTable = html.getElementsByTagName("table")
For lngTable = 0 To objTable.Length - 1
For lngRow = 0 To objTable(lngTable).Rows.Length - 1
For lngCol = 0 To objTable(lngTable).Rows(lngRow).Cells.Length - 1
ThisWorkbook.Sheets("Sheet3").Cells(ActRw + lngRow + 1, lngCol + 1) = objTable(lngTable).Rows(lngRow).Cells(lngCol).innerText
Next lngCol
Next lngRow
ActRw = ActRw + objTable(lngTable).Rows.Length + 1
Next lngTable
End Sub

我想得到如下图所示的表格
答案 0 :(得分:1)
你错过了标签名称。但是,以下方法可以从该页面获取表格数据:
Sub FetchTable()
Dim HTTP As New XMLHTTP60, HTML As New HTMLDocument
Dim trow As HTMLDivElement, tcel As HTMLDivElement, R&, C&
With HTTP
.Open "GET", "https://www.99acres.com/microsite/ambey-group-eco-valley-new-town-kolkata-east/", False
.send
HTML.body.innerHTML = .responseText
End With
For Each trow In HTML.getElementsByClassName("divTableBody")(0).Children
For Each tcel In trow.getElementsByClassName("divTableCell")
C = C + 1: Cells(R + 1, C) = tcel.innerText
Next tcel
C = 0: R = R + 1
Next trow
End Sub
答案 1 :(得分:0)
您在哪里可以使用Positioned widgets must be placed directly inside Stack widgets.
Positioned(no depth, dirty) has a Stack ancestor, but there are other widgets between them:
- Column(direction: vertical, mainAxisAlignment: start, crossAxisAlignment: center)
,而此页面上没有单个getElementsByTagName("table")
标记?它是所有DIV。
我在table
上操作,需要引用Microsoft HTML对象库,HTMLDocument
给了我一个不允许Set html = CreateObject("htmlfile")
的对象。
我删除了所有(现在)冗余变量声明。
getElementsByClassName