PDA

View Full Version : parse webpage for value



mauzzzie
Apr 18th, 2007, 03:08 PM
Hi,

For testing purposes I am trying to parse a webpage to extract some weather data off the site.


<DIV class="parent chrome5 double2" id=weather>
<H2><A href="http://travel.nl.msn.com/weer/benelux.aspx">Het weer</A></H2>
<DIV class="child c1 first">
<UL class=forecast1>
<LI class=cf>
<H4><A href="http://www.msn.nl/nieuws/weer">Amsterdam,
Noord-Holland</A></H4>Helder, 15
<UL class=cf>
<LI>
<H5>woensdag</H5><IMG height=21 alt="Licht bewolkt"
src="Welkom op MSN NL_files/30.gif" width=35>13 / 5</LI>
<LI>
<H5>donderdag</H5><IMG height=21 alt=Helder
src="Welkom op MSN NL_files/32.gif" width=35>15 / 5</LI>
<LI>
<H5>vrijdag</H5><IMG height=21 alt=Mooi src="Welkom op MSN NL_files/34.gif"
width=35>12 / 4</LI>
<LI>
<H5>zaterdag</H5><IMG height=21 alt="Licht bewolkt"
src="Welkom op MSN NL_files/30.gif" width=35>17 / 9</LI></UL></LI></UL></DIV>
<DIV class="child c2 last">
<FORM class=simple1 action=http://weather.uk.msn.com/search.aspx method=get>
<P></P>
<DIV><LABEL for=wesdaser></LABEL><INPUT class=hint id=wesdaser
title="Voer jouw stad in " accessKey=W maxLength=250 size=30
value="Weerbericht van" name=weasearchstr><INPUT class=button type=submit value=Zoek></DIV></FORM></DIV></DIV>

This is some of the data of the site. I am trying to get the "Helder, 15" value from it.
So far I cannot get past getElementById("weather")...
How can I access the desired value from there???

Can anyone please point me in the right direction?

Thanks very much...

shyam
Apr 19th, 2007, 01:55 PM
one messy way to go about it...

function extractCity() {
var w = document.getElementById('weather');
var h4 = w.getElementsByTagName('h4')[0];
// start from 1 for ffx treats ws as
for ( var i = 1; i < h4.parentNode.childNodes.length; i++ ) {
if ( h4.parentNode.childNodes[i].nodeType == 3 ) {
return h4.parentNode.childNodes[i].nodeValue;
}
}
}

mauzzzie
Apr 20th, 2007, 08:18 AM
Thanks!