I'm using DOMDocument
to get the HTML from a website. I want to get html within the <body></body>
and I got it. But inside body
here is a <nav>...</nav>
block. How can I exclude <nav></nav>
block only by using DOMDocument.
Here is my Code:
<!DOCTYPE html>
<head>
<title>Title Here</title>
<head>
<?php
$d = new DOMDocument;
$mock = new DOMDocument;
$internalErrors = libxml_use_internal_errors(true);
$d->loadHTML(file_get_contents('http://www.example.com'));
$body = $d->getElementsByTagName('body')->item(0);
foreach ($body->childNodes as $child){
$mock->appendChild($mock->importNode($child, true));
}
libxml_use_internal_errors($internalErrors);
echo $mock->saveHTML(); //<body>.....</body>
?>
</html>