时间:2021-07-01 10:21:17 帮助过:3人阅读
输出结果如下:
//将html/xml文件转换成DOM树
$dom = new DOMDocument();
$dom->loadHTMLFile("hao.html");
//得到所有class为fix的dl标签
// example 1: for everything with an id
//$elements = $xpath->query("//*[@id]");
// example 2: for node data in a selected id
//$elements = $xpath->query("/html/body/div[@id='yourTagIdHere']");
// example 3: same as above with wildcard
//$elements = $xpath->query("*/div[@id='yourTagIdHere']");
$xpath = new DOMXPath($dom);
$dls = $xpath->query('//dl[@class="fix"]');
foreach ($dls as $dl) {
$spans = $dl->childNodes;
foreach ($spans as $span) {
echo trim($span->textContent)."\t";
}
echo "\n";
}
?>
在其他位置,或者是只写上都是不识别的哦