用PHP解析HTML表
我一直在尝试使用不同的工具在站点上解析底部的表 到目前为止,我在使用简单的HTMLDOM库方面取得了最大的成功,但我仍然不知道如何只解析最后一个表 到目前为止,我的代码大致如下:用PHP解析HTML表,php,html,parsing,dom,simple-html-dom,Php,Html,Parsing,Dom,Simple Html Dom,我一直在尝试使用不同的工具在站点上解析底部的表 到目前为止,我在使用简单的HTMLDOM库方面取得了最大的成功,但我仍然不知道如何只解析最后一个表 到目前为止,我的代码大致如下: <?php require('simple_html_dom.php'); $table = array(); $html = file_get_html('http://www.waterlevels.gc.ca/cgi-bin/tide-shc.cgi?zone=20®ion=1&
<?php
require('simple_html_dom.php');
$table = array();
$html = file_get_html('http://www.waterlevels.gc.ca/cgi-bin/tide-shc.cgi?zone=20®ion=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>';
?>
如果有人对如何让库只解析最后一个表有任何建议,我们将不胜感激
谢谢您可以在
find()
调用中使用负数来获取特定元素。这将得到倒数第二个表,其中包含所有数据:
$ret = $html->find('tr', 0);
您可以在
find()
调用中使用负数来获取特定元素。这将得到倒数第二个表,其中包含所有数据:
$ret = $html->find('tr', 0);
您应该能够使用以下内容:
只需将
0
替换为正确的#您应该能够使用以下内容:
只需将0
替换为正确的#