![](/img/trans.png)
[英]How to parse a third table in a webpage using simple html dom parser in php
[英]PHP Simple HTML DOM Parser how to get Third table using find method
我有类似以下结构的HTML代码。
如何使用PHP Simple HTML DOM find方法从此HTML代码中获取第三张表的内容?
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
.......
</table>
</td>
<tr>
..........
<td>
<tr>
</tbody>
</table>
要获取第三个表,请在find方法中传递第二个参数(索引从0开始)。
$html = file_get_html(<your_file_url/html_code>);
$html->find("table", 2);
这些表是嵌套的,因此:
$dom->find("table", 0); # first table
$dom->find("table table", 0); # second table
$dom->find("table table table", 0); # third table
我不确定,但是您可以尝试以下操作:
$dom = new DomDocument;
$dom->loadXML($YourHTML);
//I have written as item(1) to point at the second table
$params = $dom->getElementsByTagName('table')->item(1);
只是一个想法,请尝试以下操作:
// Find first <table> in first <td>
$html = file_get_html('yours.htm');
$var = $html->find('td', 0)->find('table', 0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.