在php中提取HTML页面的内容 [英] Extract a content of a html page in php
本文介绍了在php中提取HTML页面的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有任何方法可以提取HTML
页面的内容,该页面从php中的<body>
开始并以</body>
结束.如果有人可以张贴一些示例代码.
There is any way to extract the content of a HTML
page that starts from <body>
and ends with </body>
in php. If there can anyone post some sample code.
推荐答案
You should have a look at the DOMDocument
reference.
此示例读取html文档,创建DOMDocument
并获取正文标签:
This example reads a html document, creates a DOMDocument
and gets the body tag:
libxml_use_internal_errors(true);
$dom = new DOMDocument;
$dom->loadHTMLFile('http://example.com');
libxml_use_internal_errors(false);
$body = $dom->getElementsByTagName('body')->item(0);
echo $body->textContent; // print all the text content in the body
您还应该检查以下资源:
You should also check out the following resources:
这篇关于在php中提取HTML页面的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文