我试图从td级导入innertext。获得大量额外的文字

时间:2017-03-01 22:07:19

标签: vba excel-vba excel

我试图获取' wfm-bodyText'的innertext。所以,我想循环浏览网页上的项目并导入,在这种情况下,导入' H.验证玩家是否正确'

enter image description here

我认为下面的脚本可行,但它实际上给了我各种额外的文字!!

Public Sub CopyFromURL()
Dim IE As InternetExplorer, doc As HTMLDocument
Dim thisClass As IHTMLElement2, thisLink As IHTMLElement
Dim rng As Range, cell As Range
Const READYSTATE_COMPLETE As Integer = 4
Dim TR_col As Object, TR As Object
Dim TD_col As Object, TD As Object
Dim row As Long, col As Long
row = 1
'Set rng = Range("A1:A5")
'For Each cell In rng

    Set IE = CreateObject("InternetExplorer.Application")
    IE.Navigate URL

    Do While (IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE)
        DoEvents
    Loop

    Set TR_col = IE.Document.getElementsByTagName("TR")

    For Each TR In TR_col
        Set TD_col = TR.getElementsByTagName("TD")

        row = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).row
            col = 1

            For Each TD In TD_col
                Cells(row, col) = TD.innerText
                col = col + 1
            Next
        row = row + 1
    Next

'Next cell
IE.Quit
End Sub

URL位于防火墙后面。我无法分享。

同样,下面是页面的结构。我想复制&#39; E。验证电话号码(如果适用)&#39;进入我的表。

enter image description here

我尝试了下面的脚本,试图从页面中获取每个元素。

Sub DumpData()

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

URL = "http://www.SharePoint.aspx"

'Wait for site to fully load
IE.Navigate2 URL
Do While IE.Busy = True
   DoEvents
Loop

RowCount = 1

With Sheets("Sheet1")
   .Cells.ClearContents
   RowCount = 1
   For Each itm In IE.document.all

      .Range("A" & RowCount) = itm.tagname
      .Range("B" & RowCount) = itm.ID
      .Range("C" & RowCount) = itm.classname
      .Range("D" & RowCount) = Left(itm.innertext, 1024)

      RowCount = RowCount + 1
   Next itm
End With
End Sub

我仍然无法说明相关数据的来源。

0 个答案:

没有答案