时间: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";
}
?>
在其他位置,或者是只写上都是不识别的哦http://www.bkjia.com/PHPjc/813508.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/813508.htmlTechArticle事情的起源比较简单,我需要把一个导航页的数据整理好写入数据库。一个比较直观的方法是对html文件进行分析,通用的方法是用php的正则...