Php Goutte Web Crawler

Viewed 56

Hello I'm creating web crawler with PhP Goutte based on wordpress admin page, i'm looking for a function, that can get links from whole website, actually it's getting only from homepage, how could I follow links, without 1000 forloops. ?

 $url = "http://example.com/"; 
$client = new Client(); 
$crawler = $client->request('GET', $url); 
$links_count = $crawler->filter('a')->count(); 
$all_links = [];

    if($links_count > 0){

        $links = $crawler->filter('a')->links();
        

        foreach ($links as $link) {
            $all_links[] = $link->getURI();
            

        }

        $all_links = array_unique($all_links);

        echo "All Avialble Links From this page $url Page<pre>"; print_r($all_links);echo "</pre>";

    } else {

        echo "No Links Found";

    }

    die;

Any ideas how can i figure it out ?

0 Answers
Related