Created
November 16, 2015 16:13
-
-
Save JaviPedrera/57a8e90348e075f9fc95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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