我可以下载内部文本,但不能下载确切的表格
我尝试使用内部文本,但只给出了整行的文本
Private Sub CommandButton1_Click()
Dim i As Integer
Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLInput As MSHTML.IHTMLElement
Dim HTMLAs As MSHTML.IHTMLElementCollection
Dim HTMLA As MSHTML.IHTMLElement
Dim tdocs As Object
Dim iframeDoc As MSHTML.HTMLDocument
IE.Visible = True
IE.navigate "https://portal.3gpp.org/#55931-tdocs"
Do While IE.ReadyState <> READYSTATE_COMPLETE
Loop
Set HTMLDoc = IE.Document
Set tdocs = HTMLDoc.getElementsByName("lt-55931-tdocs")
tdocs(0).Click
Set iframeDoc = HTMLDoc.frames("dnn_ctr559_View_ctl00_ctl01_ctr596_ETSIFrame_htmModule").Document
Dim img As MSHTML.IHTMLElement
Set img = iframeDoc.getElementById("btnSearch")
img.Click
Application.Wait (Now + TimeValue("0:00:59")) '30sec
End If
For i = 1 To 2000
Set img = iframeDoc.getElementById("rgTdocList_ctl00__" & i)
Range("A" & i) = img.innerText
End Sub
我将一行放在一列中,但我希望它们与网页上的原始样子一样
答案 0 :(得分:2)
您可以执行以下操作:
'...
'...
Application.Wait (Now + TimeValue("0:00:30")) '30sec
Dim tds, x
For i = 1 To 2000
Set img = iframeDoc.getElementById("rgTdocList_ctl00__" & i)
If img Is Nothing Then Exit For 'no more rows
Set tds = img.getElementsByTagName("td") '<< get cells for this row
'write out each cell's content
For x = 0 To tds.Length - 1
Cells(i, x + 1) = tds(x).innerText
Next x
Next i