如何使用getElementsByTagName和<td>溢出:隐藏在VBA上?

我正在使用VBA自动化来获取我工作中票据系统的一些信息。 我正在试图将值存入生成的表中,但是只有工作表“Plan1”上的列“A”的信息是<td>其中包含溢出:隐藏的CSS属性。 我不知道他们是否是相关的,但恰巧是唯一没有出现的数据。 有人可以帮助我吗?

HTML代码:

 <div id="posicionamentoContent"> <table class="grid"> <thead>...</thead> <tbody> <tr id="937712" class="gridrow"> <td width="200px"> Leonardo Peixoto </td> <td width="200px"> 23/12/2015 09:45 </td> <td width="200px"> SIM </td> <td width="200px"> Telhado da loja com pontos de vazamento.</td> <td width="200px" align="center"></td> <td width="200px" align="center"></td> </tr> ... ... ... 

完整的代码: http : //i.stack.imgur.com/4BsFo.png

我需要得到第一个第四个文本(Leonardo Peixoto,23/12/2015 09:45,SIM和Telhado da loja com pontos de vazamento),但他们只是我无法得到的文本。

Obs:当我使用开发人员工具(f12)来检查每个元素时,它会完全显示我在<td>需要的信息。 但是当我打开“源代码”页面来检查html时,代码是这样的:

 <div id="tabPosicionamento" style="padding: 5px 0 5px 0;" class="ui-tabs-hide"> div id="posicionamentoContent"></div> </div> 

示例VBA:

  Sub extractTablesData1() 'we define the essential variables Dim IE As Object, obj As Object Dim ticket As String Set IE = CreateObject("InternetExplorer.Application") ticket= InputBox("Enter the ticket code") With IE .Visible = False .navigate ("https://www.example.com/details/") & ticket While IE.ReadyState <> 4 DoEvents Wend ThisWorkbook.Sheets("Plan1").Range("A1:K500").ClearContents Set data = IE.document.getElementsByClassName("thead")(0).getElementsByTagName("td") i = 0 For Each elemCollection In data ThisWorkbook.Sheets("Plan1").Range("A" & i + 1) = data(i).innerText i = i + 1 Next elemCollection End With IE.Quit Set IE = Nothing .... .... End Sub 

这个函数只返回工作表Plan1的 “A”列中,但是我需要<td class=info1"></td><td class=info1"></td> <td class=info2 also."></td>

由于代理阻止了我,我无法阅读页面代码,但是前一段时间我遇到了类似的问题,我find的解决scheme是将所有数据放在剪贴板上并粘贴。 之后,我清理工作表上的数据。

这里是我用来做的代码:

 Set ieTable = ie.document.getElementById("ID") If Not ieTable Is Nothing Then Set clip = New DataObject clip.SetText "<html>" & ieTable.outerHTML & "</html>" clip.PutInClipboard Sheet1.Range("A1").Select ActiveSheet.PasteSpecial Format:="Unicode Text", link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True End If 

考虑到你需要隔离4个TD线,你可以做一个循环为每个search。

在您的示例中,它会计算数据,但不会使用它。 此外,单元格分配应该是单元格(x,y).value。 这是工作代码。

 Sub extractTablesData1() 'we define the essential variables Dim IE As Object, Data As Object Dim ticket As String Set IE = CreateObject("InternetExplorer.Application") With IE .Visible = False .navigate ("put your data url here") While IE.ReadyState <> 4 DoEvents Wend Set Data = IE.document.getElementsByTagName("tr")(0).getElementsByTagName("td") i = 1 For Each elemCollection In Data ActiveWorkbook.Sheets(1).Cells(1, i).Value = elemCollection.innerHTML i = i + 1 Next elemCollection End With IE.Quit Set IE = Nothing End Sub 

它没有带来我需要的信息(持续时间<td>

 <div id="posicionamentoContent"> <table class="grid"> <thead>...</thead> <tbody> <tr id="937712" class="gridrow"> <td width="200px"> Leonardo Peixoto </td> <td width="200px"> 23/12/2015 09:45 </td> <td width="200px"> SIM </td> <td width="200px"> Telhado da loja com pontos de vazamento.</td> <td width="200px" align="center"></td> <td width="200px" align="center"></td> </tr>