我有一个像这样的html文件:
<table class="table stage">
<thead> ... </thead>
<tbody>
<tr>
<td>1</td>
<td>6</td>
<td>3</td>
<td>6</td>
<td>4</td>
<td>2</td>
<td>0</td>
<td>9</td>
<td>3</td>
<td>6</td>
<td>14</td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr></tr>
</tbody>
如何获取特定td标签的内容? tr和td标签没有任何id或类。唯一的类名是表标记。我有这个代码芽,它只返回thead内容:
<?php
$dochtml = new DOMDocument();
$dochtml->loadHTMLfile('http://url.com');
$finder = new DomXPath($dochtml);
$classname='table';
$nodes = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' $classname ')]");
echo $nodes->item(0)->firstChild->nodeValue;
?>