I have HTML code like following structure.
How can I fetch the 3rd table's content from this HTML code using PHP Simple HTML DOM find method?
<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>
To get third table pass second argument(index start from 0) in find method.
$html = file_get_html(<your_file_url/html_code>);
$html->find("table", 2);
The tables are nested so:
$dom->find("table", 0); # first table
$dom->find("table table", 0); # second table
$dom->find("table table table", 0); # third table
I am not that sure but you can try something like below:
$dom = new DomDocument;
$dom->loadXML($YourHTML);
//I have written as item(1) to point at the second table
$params = $dom->getElementsByTagName('table')->item(1);
just an idea, try this:
// Find first <table> in first <td>
$html = file_get_html('yours.htm');
$var = $html->find('td', 0)->find('table', 0);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.