在php中提取html页面的内容

bha*_*thi -2 php html-content-extraction

有任何方法可以提取以php HTML开头<body>和结尾的页面内容</body>.如果有人可以发布一些示例代码.

Cyc*_*ode 6

你应该看一下DOMDocument参考文献.

此示例读取html文档,创建DOMDocument并获取body标记:

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
Run Code Online (Sandbox Code Playgroud)

您还应该查看以下资源:

DOM API文档
XPATH语言规范