Consulting

Results 1 to 4 of 4

Thread: Need help with inspecting elements from website

  1. #1
    VBAX Newbie
    Joined
    Apr 2014
    Posts
    2
    Location

    Need help with inspecting elements from website

    Dear all,

    I am a beginner at VBA and i am recently working on making a flight and flight status lookup. However, i am stuck on grabbing the status data, shown as below highlighted data:



    I have tried various set of codes, however i just cant manage to get the one i want. Can anyone pls provide me some advice. Thanks everyone!

    Here are the codes i am using right now:

    Private Sub Worksheet_Change(ByVal Target As Range)
     If Target.Row = Range("Flight").Row And _
     Target.Column = Range("Flight").Column Then
       Dim IE As New InternetExplorer
       IE.Visible = True
       IE.navigate "URLlink" & Range("Flight").Value
       Do
        DoEvents
       Loop Until IE.readyState = READYSTATE_COMPLETE
       Dim Doc As HTMLDocument
       Set Doc = IE.document
       Dim sTD As String
       sTD = Trim(Doc.getElementById("list").getElementsByTagName("td")(4).innerText)
       MsgBox sTD
     End If
    End Sub

  2. #2
    what are you getting in the messagebox now?

    i am really struggling to read what is in the image, perhaps you should post it as html code

  3. #3
    VBAX Newbie
    Joined
    Apr 2014
    Posts
    2
    Location
    Thanks for the reply !

    Here are the code I got from the website:


    HTML Code:
    <head>...</head>
    <body style="background-color: rgb(255, 255, 255);" onload="setTimeout(chgList, 0)">
    <script language="javascript" src="/eng/include/announcement.js" type="text/javascript"></script>
    <div id="announceWrapper">   
    <div id="loading" style="left: 260px; top: 50px; display: none; position: absolute;"><img src="img/loading.gif"></div>
    <h1 style="margin: 0px; padding: 0px; color: white; font-size: 1px;">Real Time Flight Information</h1>
    <table width="100%" id="list" border="0" cellspacing="0" cellpadding="2">
    <tbody>
    <tr style="display: none;" date="13 APRIL 2014,2014-4-13">
    <td>20:30</td>
    <th style="width: 59px;">CX 473,KA 5473</th>
    <td ap=",TPE,">Taipei</td>
    <td al=",CPA,HDA,">wmocpa,Cathay Pacific,wmohda,Dragonair</td>
    <td hall="B">B</td>
    <td>At gate 00:05 (14/4/2014)</td>

    Since I saw the table id is "list" and the element I am looking for is the 4th <td> item which is "<td>At gate 00:05 (14/4/2014)</td>" , so I used Doc.getElementById("list").getElementsByTagName("td")(4).innerText, however the msgbox comes out and says "Object variable not set (Error 91)".

  4. #4
    try break it down into steps to find where problem is

    set tbl = Doc.getElementById("list")
    set tds = tbl.ElementsByTagName("td")
    msgbox tds(4).innertext
    make sure each object is valid, or which is failing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •