keyaspects
Member
Posted 7 months ago #
Hi, try to grab specific content from a website (have permission). But instead of grabbing the whole page I want to grab the content surround within the div named 'main'.
I have the following so far but this just displays the whole page.
<?php
$ch = curl_init("http://www.......");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
?>
keyaspects
Member
Posted 7 months ago #
I have the following now but this only grabs the text (no images)..
<?php $page = file_get_contents('http://www.testsite/testpage3.php');
$doc = new DOMDocument();
$doc->loadHTML($page);
$divs = $doc->getElementsByTagName('div');
foreach($divs as $div) {
if ($div->getAttribute('id') === 'main') {
echo $div->nodeValue;
}
}
?>