如何在不丢失标签的情况下抓取网页数据 [英] how to scrape web page data without losing tags
本文介绍了如何在不丢失标签的情况下抓取网页数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< p>
和 ; br>
缺少。所以我把所有的段落连接起来。如何解决这个问题解决方案
如果你有一个节点,你需要所有的内容,你可以使用这个功能:
function innerHTML(DOMNode $ node)
{
$ doc = new DOMDocument();
foreach($ node-> childNodes as $ child){
$ doc-> appendChild($ doc-> importNode($ child,true));
}
return $ doc-> saveHTML();
}
I am trying to scrape web data using php and dom xpath. When I store the $node->nodeValue into my database or even if i try to echo it, all the tags like <p>
and <br>
are missing. So I am getting all the paras concatenated. How to solve this problem
解决方案
If you have a node, and you need all its contents as they are, you can use this function:
function innerHTML(DOMNode $node)
{
$doc = new DOMDocument();
foreach ($node->childNodes as $child) {
$doc->appendChild($doc->importNode($child, true));
}
return $doc->saveHTML();
}
这篇关于如何在不丢失标签的情况下抓取网页数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文