仅获取第一个表中的表行 - Simple HTML Dom(PHP)

时间:2016-12-06 14:40:07

标签: php html html-table simple-html-dom



<table border="3" rules="all" cellpadding="1" cellspacing="1">
  <tbody>
    <tr>
      <td align="center">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial" color="#000000">  <b>Maandag</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>Dinsdag</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>Woensdag</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>Donderdag</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>Vrijdag</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr>
      <td rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>1</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="18" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *verlof  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_4.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O114  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V6A  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V6C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr></tr>
    <tr>
      <td rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>2</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_3.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O114  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V4B  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V4C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_7.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V4B  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V4A  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr></tr>
    <tr>
      <td rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>3</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_1.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V6A  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V6C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_1.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V6A  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V6C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr></tr>
    <tr>
      <td rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>4</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr></tr>
    <tr>
      <td rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>5</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  stip  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  Os1  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_5.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V5B  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V5C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_5.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V5B  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V5C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr></tr>
    <tr>
      <td rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>6</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_3.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V4B  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V4C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_3.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V4B  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V4C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr></tr>
    <tr>
      <td rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>7</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_4.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V6A  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V6C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_7.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V4B  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V4A  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_4.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V6A  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V6C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_7.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V4B  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V4A  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr></tr>
    <tr>
      <td rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>8</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_5.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V5B  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V5C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_1.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V6A  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V6C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr></tr>
    <tr>
      <td rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>9</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr></tr>
  </tbody>
</table>
&#13;
&#13;
&#13; 我的学校为我提供了以下时间表(如上所示),但是当我想使用simplehtmldom解析表时。从这张表我想收集数据,以便我可以在我的应用程序中使用它。

simplehtmldom中的哪些查询可用于仅选择第一个表行? 像这样:表 - &gt; (所有行)

当我尝试此查询时:echo($html->find('table tr',0));我将零更改为2(例如),它不会返回主表的下一个表行。但相反,它返回第一个表行中子表的frist表行。

并非我无法改变表格的呈现方式,这是我必须使用的表格。

执行时我现在得到的内容:echo($html->find('table tr',2)); - &gt; &#34; Maandag&#34;

我想得到的是:<tr><td rowspan="2" align="center" nowrap="1"><table><tbody><tr><td align="center" nowrap="1"><font size="2" face="Arial"> <b>2</b> </font> </td> </tr></tbody></table></td> <td colspan="12" rowspan="2" align="center" nowrap="1"><table><tbody><tr><td></td></tr></tbody></table></td> <td colspan="12" rowspan="2" align="center" nowrap="1"><table><tbody><tr><td width="33%" nowrap="1"><font size="2" face="Arial"> *in_3. </font> </td> <td width="33%" nowrap="1"><font size="2" face="Arial"> O114 </font> </td> <td width="33%" nowrap="1"><font size="2" face="Arial"> V4B </font> </td> </tr><tr><td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V4C </font> </td> </tr></tbody></table></td> <td colspan="12" rowspan="2" align="center" nowrap="1"><table><tbody><tr><td width="33%" nowrap="1"><font size="2" face="Arial"> *in_7. </font> </td> <td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font> </td> <td width="33%" nowrap="1"><font size="2" face="Arial"> V4B </font> </td> </tr><tr><td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V4A </font> </td> </tr></tbody></table></td> <td colspan="12" rowspan="2" align="center" nowrap="1"><table><tbody><tr><td></td></tr></tbody></table></td></tr> (第一个(主要)表的下一个表格)

我在html表中加载的方式:

$html = file_get_html($timetableURL);
$timeTable = $html->find('table',0); //I need to do this because the page with the timetable has more html tables, I tested this and it always fetches the timetable as seen above.

相关问题:PHP Simple HTML DOM Parser how to get TR only from first table 我只想选择第一个表的第二行或第三行。

echo($timeTable->find('tr',2));

4 个答案:

答案 0 :(得分:1)

简单的html-dom有点令人费解:

// find the first table
$table = $html->find('table', 0);

// iterate all tr's
foreach($table->find('tr') as $tr){

  // skip the tr's that are not top level
  if($tr->parent->parent != $table) continue;

  do_something_with($tr);
}

答案 1 :(得分:1)

我使用了while循环和simple-html-dom nextSibling()函数。

$tableCell = $row->find('td', 0);
while($tableCell){
   $tableCell = $tableCell->next_sibling(); //Go to the next tableCell
}

答案 2 :(得分:0)

您可以使用jQuery选择器:first从DOM中获取第一个元素

你可以这样做:

$(function() {
	var table = $('table:first');
	var table_rows = table.find('tr');
	alert(" There are " + table_rows.length + " rows in Table");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table border="3" rules="all" cellpadding="1" cellspacing="1">
  <tbody>
    <tr>
      <td align="center">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial" color="#000000">  <b>Maandag</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>Dinsdag</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>Woensdag</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>Donderdag</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>Vrijdag</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr>
      <td rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>1</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="18" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *verlof  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_4.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O114  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V6A  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V6C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr></tr>
    <tr>
      <td rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>2</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_3.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O114  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V4B  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V4C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_7.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V4B  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V4A  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr></tr>
    <tr>
      <td rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>3</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_1.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V6A  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V6C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_1.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V6A  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V6C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr></tr>
    <tr>
      <td rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>4</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr></tr>
    <tr>
      <td rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>5</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  stip  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  Os1  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_5.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V5B  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V5C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_5.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V5B  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V5C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr></tr>
    <tr>
      <td rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>6</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_3.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V4B  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V4C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_3.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V4B  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V4C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr></tr>
    <tr>
      <td rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>7</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_4.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V6A  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V6C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_7.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V4B  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V4A  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_4.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V6A  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V6C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_7.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V4B  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V4A  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr></tr>
    <tr>
      <td rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>8</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_5.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V5B  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V5C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  *in_1.  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  O112  </font> 
              </td>
              <td width="33%" nowrap="1"><font size="2" face="Arial">  V6A  </font> 
              </td>
            </tr>
            <tr>
              <td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial">  V6C  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr></tr>
    <tr>
      <td rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td align="center" nowrap="1"><font size="2" face="Arial">  <b>9</b>  </font> 
              </td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
      <td colspan="12" rowspan="2" align="center" nowrap="1">
        <table>
          <tbody>
            <tr>
              <td></td>
            </tr>
          </tbody>
        </table>
      </td>
    </tr>
    <tr></tr>
  </tbody>
</table>

希望这有帮助!

答案 3 :(得分:0)

遍历您的DOM结构,我发现您想要的tr是第4个子tr,它直接位于tbody下的table元素下。

因此,您需要的查询可能是这样的

// assume table is the root/parent DOM
$tr = $table->find('tbody > tr:nth-child(4)');
var_dump($tr->html());

很抱歉,如果php语法不正确。这实际上是针对phpquery库进行测试的。