Skip to content

Instantly share code, notes, and snippets.

@JaviPedrera
Created November 16, 2015 23:44
Show Gist options
  • Save JaviPedrera/687415fd971e9f9811e2 to your computer and use it in GitHub Desktop.
Save JaviPedrera/687415fd971e9f9811e2 to your computer and use it in GitHub Desktop.
<?php
// Require de Simple HTML DOM Library
require 'simple_html_dom.php';
// Get HTML from the URL by using a method from the library
$html = file_get_html('https://es.search.yahoo.com/search?p=madrid&fr=yfp-t-777');
// Get the corresponding div with the search results
$div = $html->find('div[id=web]', 0);
// Count the number of results
$resultsCount = 0;
foreach ($div->find('h3') as $titles) {
$resultsCount++;
}
// Creating arrays for the tags
$titles = array();
$bodies = array();
$links = array();
$cache = array();
// Iterate the tags and print the content
for ($i = 0; $i < $resultsCount; $i++) {
$titles[] = $div->find('h3', $i)->innertext;
$links[] = $div->find('span', $i)->innertext;
$cache[] = $div->find('a', $i)->innertext;
$bodies[] = $div->find('p', $i)->innertext;
echo strip_tags($titles[$i]);
echo "<br/>";
echo strip_tags($links[$i]) . " - " . strip_tags($cache[$i]);
echo "<br/>";
echo strip_tags($cache[$i]);
echo "<br/>";
echo "<br/>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment