0

I have been trying to parse the bottom table on this site using different tools.

So far I have had the greatest success using the Simple HTML Dom library, but I still cannot figure out how to parse only that last table.

So far my code is something along the lines of:

<?php

require('simple_html_dom.php');

$table = array();

$html = file_get_html('http://www.waterlevels.gc.ca/cgi-bin/tide-shc.cgi?zone=20&region=1&   language=english&station=9635&queryType=predict&year=2012&month=2&day=9&view=table&TZ=PST');

foreach($html->find('tr') as $row) 
{
//confused as what to do there to parse only last table in given URL
}

echo '<pre>';
print_r($table);
echo '</pre>';

?>

If someone has any suggestiong as how to get the library to only parse the last table it would be greatly appreciated.

Thanks

0

2 Answers 2

3

You can use a negative number in the find() call to get a specific element. This should get you the second-to-last table, which contains all of the data:

$table = $html->find('table',-2);
foreach($table->find('tr') as $row)
{
  // Process each row
}
Sign up to request clarification or add additional context in comments.

Comments

0

You should be able to use something like this:

$ret = $html->find('tr', 0);

Just replace 0 with the correct #

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.