![](/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.