<?php // Html $html = file_get_contents('https://es.search.yahoo.com/search?p=madrid&fr=yfp-t-777'); // Creating instance of DOMDocument and loading the HTML $dom = new DOMDocument; libxml_use_internal_errors(TRUE); $dom->loadHTML($html); libxml_use_internal_errors(FALSE); // Getting the container with the desired results $container = $dom->getElementById('web'); // Fetching results grouped by tags $titles = $container->getElementsByTagName('h3'); $links = $container->getElementsByTagName('a'); $cache = $container->getElementsByTagName('span'); $bodies = $container->getElementsByTagName('p'); // Getting the number of results $resultsCount = 0; foreach ($container->getElementsByTagName('h3') as $title) { $resultsCount++; } // Iterating and printing tag values $i = 0; while ($i < $resultsCount) { echo $titles[$i]->nodeValue; echo "<br/>"; echo $links[$i]->nodeValue . " - " . $cache[$i]->nodeValue; echo "<br/>"; echo $bodies[$i]->nodeValue; echo "<br/>"; echo "<br/>"; $i++; }