我有HTML代码,如下面的结构。
如何使用PHP Simple HTML DOM find方法从此HTML代码中获取第3个表的内容?
<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>
答案 0 :(得分:4)
在find方法中获取第三个表传递第二个参数(索引从0开始)。
$html = file_get_html(<your_file_url/html_code>);
$html->find("table", 2);
答案 1 :(得分:2)
这些表是嵌套的:
$dom->find("table", 0); # first table
$dom->find("table table", 0); # second table
$dom->find("table table table", 0); # third table
答案 2 :(得分:0)
我不确定,但您可以尝试下面的内容:
$dom = new DomDocument;
$dom->loadXML($YourHTML);
//I have written as item(1) to point at the second table
$params = $dom->getElementsByTagName('table')->item(1);
答案 3 :(得分:0)
只是一个想法,试试这个:
// Find first <table> in first <td>
$html = file_get_html('yours.htm');
$var = $html->find('td', 0)->find('table', 0);