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

时间:2017-04-13 08:40:42

标签: php parsing dom

我使用下面的代码但是从链接我不能解析所有股票数据的值。有人可以帮我吗?

<?php
// Include the library
include('simple_html_dom.php');

// Retrieve the DOM from a given URL
$html = file_get_html('http://www.dsebd.org/dseX_share.php');


// Extract all text from a given cell
echo $html->find('td[align="center"]', 1)->plaintext.'<br><hr>';

1 个答案:

答案 0 :(得分:-1)

<?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>';
?>