且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

不能用PHP简单的HTML DOM解析器解析网页

更新时间:2022-03-12 22:26:07

<?php

ini_set('display_errors', 1);
include_once('simple_html_dom.php');

$html = file_get_html('http://www.dsebd.org/dseX_share.php');
$table = $html->find('table', 5);

$rowData = array();

foreach ($table->find('tr') as $row)
{
    foreach ($row->find('td') as $cell)
    {
        $flight = array();
        $cell->plaintext=  preg_replace('/<\/[\w]+>/',"",$cell->plaintext);
        $flight[] = array_map('trim', preg_split("@(\&nbsp;)+@", $cell->plaintext));
    }
    $rowData=array_merge($rowData,$flight);
}
print '<pre>';
print_r($rowData);
print '</pre>';
?>