Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Get the html returned from the following url and scrape from it
- $html = file_get_contents('http://www.phoenixpark.ie/newsevents/2013/title,24194,en.html');
- $park_doc = new DOMDocument(); // Declare a new DOM object
- libxml_use_internal_errors(TRUE); // Disable libxml errors
- if(!empty($html)) // If any html is actually returned
- {
- $park_doc->loadHTML($html);
- libxml_clear_errors(); //remove html errors
- $xpath = new DOMXPath($park_doc); //DOMXPath allows queries with the DOM document.
- // Perform xpath query to find information
- $event_title = $xpath->query('//h1[not(@class)]'); //gets the event title, ignores any other h1 headings on the page
- }
- //-------------------------CONNECTION AND INSERTION INTO DATABASE---------------------------
- $username = 'root';
- $password = '';
- $database = 'park';
- $host = 'localhost';
- $con = mysqli_connect($host, $username, $password, $database);
- // Check connection
- if (mysqli_connect_errno())
- echo "Failed to connect to MySQL: " . mysqli_connect_error();
- else
- echo "</br></br>Connected...</br>";
- //Check if database is found
- $db_found = mysqli_select_db($con, $database)or die("cannot select DB");
- if ($db_found)
- {
- print "Database Found </br>";
- //Insert into the database
- mysqli_select_db($con, $database)or die("cannot select DB");
- $sql = "INSERT INTO events (title)
- VALUES
- ('$event_title')";
- mysqli_query($con, $sql);
- print "Inserted";
- }
- else
- print "Database NOT Found ";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement