我正在使用loadHTMLFile
从HTML页面获取表格的td内容,它运行正常,
define('GLPI_ROOT', '..');
$dom = new DOMDocument();
$dom->loadHTMLFile(GLPI_ROOT . "/front/yourpage.html");
$tables = $dom->getElementsByTagName('table');
$table = $tables->item(9);
$ana = $table->getElementsByTagName('td');
foreach ($ana as $td) {
if ($td->nodeName == 'td') {
echo $td->nodeValue,"<br/>";
}
}
但我真正想要的只是获取td
tr
元素的第二个table
元素
答案 0 :(得分:0)
您可以尝试这样的事情:
$cnt= 0;
foreach ($ana as $td) {
if ($td->nodeName == 'tr')
$cnt= 0;
else
$cnt++;
if ($td->nodeName == 'td' && $cnt == 2) {
echo $td->nodeValue,"<br/>";
}
}