WordPress.org

Ready to get started?Download WordPress

Forums

grab specific content from a website into a wordpress page (2 posts)

  1. keyaspects
    Member
    Posted 2 years 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);
    			?>
  2. keyaspects
    Member
    Posted 2 years 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;
    			}
    		}
    
    			?>

Topic Closed

This topic has been closed to new replies.

About this Topic