Advertisement
colmulhall

Untitled

Apr 2nd, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.87 KB | None | 0 0
  1. <?php
  2.     // Get the html returned from the following url and scrape from it
  3.     $html = file_get_contents('http://www.phoenixpark.ie/newsevents/2013/title,24194,en.html');
  4.  
  5.     $park_doc = new DOMDocument();  // Declare a new DOM object
  6.  
  7.     libxml_use_internal_errors(TRUE); // Disable libxml errors
  8.  
  9.     if(!empty($html))    // If any html is actually returned
  10.     {
  11.       $park_doc->loadHTML($html);
  12.       libxml_clear_errors(); //remove html errors
  13.      
  14.       $xpath = new DOMXPath($park_doc);  //DOMXPath allows queries with the DOM document.
  15.      
  16.       //perform queries to find information
  17.       $event_title = $xpath->query('//h1[not(@class)]');  //gets the event title, ignores any other h1 headings on the page
  18.      
  19.       // Display contents of the scrape
  20.       if($event_desc->length > 0)
  21.       {
  22.           foreach($event_title as $row)
  23.           {
  24.               echo $row->nodeValue . "<br/>";
  25.           }
  26.       }
  27.     }
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement