返回清理器简单的HTML DOM数组

时间:2013-07-03 20:53:51

标签: php html-parsing simple-html-dom

我使用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 : ) 

1 个答案:

答案 0 :(得分:0)

您只需使用预标签:

<pre>

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

</pre>

这样做是为了从print_r的结果为空格和换行生成正确的HTML。

相关问题