返回更干净的简单HTML DOM数组



Im使用Simple HTML Dom从页面上的表返回数组,该表类似于以下

<table width="414" cellspacing="4" cellpadding="0" border="0">
<tbody>
<tr>
<td width="170">Total :</td>
<td>58,262</td>
</tr>
... // there are about another 10 <tr> tags, and table closing tags after that.

但是,当我运行命令print_r($es = $html->find('table[width=414]'));时,我返回了一个巨大的数组(与它的解析相反),下面的例子将我们带到第一行"Total:",下一行大约是下面的200行。有什么想法可以让我得到一个更"净化"的结果吗?

Array ( [0] => simple_html_dom_node Object ( [nodetype] => 1 [tag] => table [attr] => Array ( [cellpadding] => 0 [cellspacing] => 4 [border] => 0 [width] => 414 ) [children] => Array ( [0] => simple_html_dom_node Object ( [nodetype] => 1 [tag] => tr [attr] => Array ( ) [children] => Array ( [0] => simple_html_dom_node Object ( [nodetype] => 1 [tag] => td [attr] => Array ( [width] => 170 ) [children] => Array ( ) [nodes] => Array ( [0] => simple_html_dom_node Object ( [nodetype] => 3 [tag] => text [attr] => Array ( ) [children] => Array ( ) [nodes] => Array ( ) [parent] => simple_html_dom_node Object *RECURSION* [_] => Array ( [4] => Total : ) 

您只需要使用预标记:

<pre>
    <?php print_r($es = $html->find('table[width=414]'); ?>
</pre>

这样做的目的是根据print_r的结果为空格和换行符生成正确的HTML。

最新更新