我正在尝试使用 simplehtmldom (http://simplehtmldom.sourceforge.net/) 打印出表格的第 n 行。目前没有任何反应,我还需要做什么吗?
<?php
include 'simple_html_dom.php';
$html = file_get_html('http://www.masjid-umar.org/downloads/timetable_apr.htm');
$ret = $html->find('tr', 9);
echo $ret;
?>
假设第 9 行是 TUE 行,您也可以使用 PHP 内置的 DOMDocument 来完成此操作,这将节省一些内存和解析时间,并且不依赖于第三方脚本。
<?php
$html = file_get_contents('http://www.masjid-umar.org/downloads/timetable_apr.htm');
$dom = new DOMDocument();
@$dom->loadHTML($html);
//TUE 1 1 4.37 6.39 1.08 5.35 9.18 6.00 1.30 6.30 7.42 9.40
echo '
<table>
<tr>';
foreach($dom->getElementsByTagName('table') as $table) {
echo innerHTML($table->getElementsByTagName('tr')->item(9));
}
echo '
</tr>
</table>';
function innerHTML($current){
$ret = "";
$nodes = @$current->childNodes;
if(!empty($nodes)){
foreach($nodes as $v){
$tmp = new DOMDocument();
$tmp->appendChild($tmp->importNode($v, true));
$ret .= $tmp->saveHTML();
}
return $ret;
}
return;
}
?>
您还想考虑将结果缓存一天,因为网站速度很慢;p
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)