1

I have a web query to a table that gives me a table like this :

     [C]                  [D]             [E]
[A] Events         |   IP source    | IP destination |
[B] MyEvent (1.10) |   192.168.0.1  | 192.168.0.3    |

the Html Code that gives me the info is on this type of schema :

<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>

Soo i can get the value by the simple c0de .innerText the complete value from the innerText is :

myEvent (1.10) 192.168.0.1 192.168.0.2

I do grab this value cristal clear with msgbox , and i have this c0de in excel that what it does is , see were do you have the mouse on the worksheet and gives to a Label.form the Caption of what you got, i have 3 label.form's 1 for the Event, one for the Source Ip and one for the Destination ip and i try to see if that line that i have exists's on the table with a c0de but nothing happens.

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

Well I hope someone can see what i'm doing wrong i just want to know if there is a way to do this.

glh
  • 4,900
  • 3
  • 23
  • 40
PythonNewbie
  • 228
  • 1
  • 4
  • 12

1 Answers1

0

A few debug points:

  1. Step through your code and manually check each Trim(TRelement.innerText) value for validity.
  2. Ensure the Eventi.Caption value is exactly "myEvent (x.xx)" including the space, parenthesis and case.
  3. I'm not familiar with HTMLdoc.getElementsByTagName("TR"), but ensure it's not case sensitive.
  4. As @Dick suggested, check for any non-spaces that should be a spce using asc(mid(TRelement.innertext),8,1)), where 8 is where you think a space is. If it comes back with something other than 32 (ascii for a space), you won't get a match in your If statement.
glh
  • 4,900
  • 3
  • 23
  • 40
  • 1
    Also, do a `asc(mid(TRelement.innertext),8,1))` where 8 is where you think a space is. If it comes back with something other than 32 (ascii for a space), you won't get a match. – Dick Kusleika Apr 03 '13 at 21:56