PDA

View Full Version : Need help with inspecting elements from website



SonofRed
04-13-2014, 09:22 AM
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:

11562

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

westconn1
04-14-2014, 03:40 AM
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

SonofRed
04-14-2014, 06:06 AM
Thanks for the reply !

Here are the code I got from the website:



<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)".

westconn1
04-14-2014, 06:24 AM
try break it down into steps to find where problem is


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