Get instagram HTML [closed]

1

I have this code, but the file_get_contents does not work correctly.

  $html = file_get_contents('https://www.instagram.com/');


    $dom = new domDocument();
    $dom->loadHTML($html);
    $dom->preserveWhiteSpace = false;
    $images = $dom->getElementsByTagName('img');
    foreach ($images as $image) {
        $img_id =  $image->getAttribute('id');

        if($img_id == 'hi_2') {
            echo $image->getAttribute('src');

        }
    }

Thanks for the help!

    
asked by Pau G.P. 24.02.2017 в 10:51
source

1 answer

0

Good Pau G.P.

If you print your variable $ html you will see that there is no image tag in the body of the html returned. The code works correctly, surely all the content is loaded by ajax with javascript.

file_get_contents ('url') only gets the initial code and does not run javascript.

    
answered by 24.02.2017 в 11:35