簡體   English   中英

PHP簡單HTML DOM解析器如何使用find方法獲取第三張表

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM