Skip to content

Instantly share code, notes, and snippets.

@JaviPedrera
Created November 16, 2015 16:13
Show Gist options
  • Save JaviPedrera/57a8e90348e075f9fc95 to your computer and use it in GitHub Desktop.
Save JaviPedrera/57a8e90348e075f9fc95 to your computer and use it in GitHub Desktop.
<?php
$url = 'https://es.search.yahoo.com/search?p=madrid&fr=yfp-t-777';
$html = file_get_contents($url);
$dom = new DOMDocument;
libxml_use_internal_errors(TRUE);
$dom->loadHTML($html);
libxml_use_internal_errors(FALSE);
$finder = new DomXPath($dom);
$className = " reg searchCenterMiddle";
$node = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' $className ')]");
foreach ($node->getElementsByTagName('li') as $result) {
// Result Title
echo $result->getElementsByTagName('h3')->nodeValue;
echo "<br/>";
// URL and Caché
echo $result->getElementsByTagName('span')->nodeValue;
echo $result->getElementsByTagName('a')->nodeValue;
echo "<br/>";
// Content
echo $result->getElementsByTagName('p')->nodeValue;;
echo "<br/>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment