Search code examples
javascriptphpjqueryhtmlsimple-html-dom

Make $dom = $html->load(file_get_contents($nextLink)) wait for website to load


I have a HTML SIMPLE DOM PARSER program...

My problem is:

I'm trying to get the product links on different pages.

The links on the first page, collects no problem.

The big problem comes when I try to access the second page. There is an event that launches the product without changing the url, adding #/page-2 ... 3 ... 4 according to the page.

The problem is that the program is unable to walk toward the second page. It is always in the first, repeating the links on this.

There a way to make the program move to the second page?

This is the code I use:

I put example url, but i use $nextLink to loop for the pages.

Thanks^^

    $html = new simple_html_dom();
    $dom = $html->load(file_get_contents(http://www.perfumeriasabina.com/es/29-perfumeria-sabina-online#/page-2));
        if (!empty($dom))
        {
            $dom->find('a');
        }   
     $productos = $html->find('.product_img_link');
     foreach($productos as $producto) 
     {
       $enlaces = $producto->href; 
       echo $enlaces . "<br/>";
     }

Solution

  • With a small research on that website, just append :

    ?p=2
    

    To the url, according to the page number you want to to download, So your URL will look like :

    http://www.perfumeriasabina.com/es/29-perfumeria-sabina-online?p=2