0

I want to get all image from a website where the data store in a inner div, how can i fetch all image. I tried but it can't work. Here is my code

  <?php
$html = file_get_contents('http://en.vonvon.me/'); //get the html returned from the following url

$pokemon_doc = new DOMDocument();

libxml_use_internal_errors(TRUE); //disable libxml errors

if(!empty($html)){ //if any html is actually returned

    $pokemon_doc->loadHTML($html);
    libxml_clear_errors(); //remove errors for yucky html

    $pokemon_xpath = new DOMXPath($pokemon_doc);

    //get all the h2's with an id
    $pokemon_row = $pokemon_xpath->query('div[class=desc ng-binding]');

    if($pokemon_row->length > 0){
        foreach($pokemon_row as $row){
            echo $row->nodeValue . "<br/>";
        }
    }
}
?>
  • 1
    So, what's the issue? No or wrong output? Error messages? Checked the error log? Btw.. if your code doesn't work, you should remove the `@` signs since those suppress error messages, which are helpful when debugging. – M. Eriksson Mar 18 '17 at 11:29

1 Answers1

-2

you can't scrap websites working by JavaScript [Angular], scrappers are not seeing the DOM after the execution of JavaScript.

but in the other hand, if the images was in the dom you can use

The best thing for that is Simple HTML DOM Parser

$html = file_get_html('http://vonvon.me/');

// Find all images 
foreach($html->find('img') as $element) 
       echo $element->src . '<br>';
Moustafa Elkady
  • 670
  • 1
  • 7
  • 17