我有一个表格的网页查询,它给我一个这样的表格:
[C] [D] [E]
[A] Events | IP source | IP destination |
[B] MyEvent (1.10) | 192.168.0.1 | 192.168.0.3 |
给我信息的Html代码就是这种类型的架构:
<table class="wrapper">
<tbody>
<tr>
<td width="100%" valign="top">
<center>
<div id="contenpanel">
<table id="contenttable" class="full_table_of_events">
<tbody>
<tr class="content" oncontextmenu="blablabla",( "src=192.168.0.1&dst=192.168.0.2")></tr>
<tr></tr>
<tr></tr>
</tbody>
</table>
</div>
</center>
</td>
<tr>
</tbody>
</table>
所以我可以通过简单的c0de .innerText获取内部文本中的完整值:
myEvent (1.10) 192.168.0.1 192.168.0.2
我确实用msgbox获取了这个值cristal clear,并且我在excel中有这个c0de它的功能是什么,看看你是否在工作表上有鼠标并给了Label.form你得到的标题,我有3个label.form的1为事件,一个为Source Ip,另一个为Destination ip,我试着看看我存在的那条线是否存在于c0de的桌子上,但没有任何反应。
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Eventi.Caption = ActiveCell.Value
Source.Caption = Cells(ActiveCell.Row, ActiveCell.Column + 1)
Destination.Caption = Cells(ActiveCell.Row, ActiveCell.Column + 2)
End Sub
Sub Extract()
Dim URL As String
Dim IE As InternetExplorer
Dim HTMLdoc As HTMLDocument
Dim TRelements As IHTMLElementCollection
Dim TRelement As HTMLTableRow
Dim Chkb0x As IHTMLElementCollection
URL = "https://localhost/events/index.cgi"
Set IE = New InternetExplorer
With IE
.navigate URL
.Visible = True
While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
Set HTMLdoc = .document
End With
Set TRelements = HTMLdoc.getElementsByTagName("TR")
MsgBox Eventi.Caption & " " & Source.Caption & " " & Destination.Caption
MsgBox "Search Starting..."
For Each TRelement In TRelements
If Trim(TRelement.innerText) = Eventi.Caption & " " & Source.Caption & " " & Destino.Caption Then
MsgBox "Bingo! You have this event"
End If
Next
End Sub
嗯,我希望有人能看到我做错了什么,我只想知道是否有办法做到这一点。
答案 0 :(得分:0)
一些调试点:
Trim(TRelement.innerText)
值的有效性。Eventi.Caption
值完全符合&#34; myEvent(x.xx)&#34;包括空格,括号和案例。HTMLdoc.getElementsByTagName("TR")
,但请确保它不区分大小写。asc(mid(TRelement.innertext),8,1))
检查任何应该是spce的非空格,其中8是您认为空格的位置。如果它返回的不是32(ascii表示空格),则表示您在If
声明中未获得匹配。