在php中提取HTML页面的内容 [英] Extract a content of a html page in php

查看:1068
本文介绍了在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:

DOM API文档
XPATH语言规范

这篇关于在php中提取HTML页面的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆