dimanche 26 juin 2016

Retrieving all instagram comments [Web scraping]

I'm working on a project so that we should write an application to retrive all instagram comments of a photo.

My code:

<?php
$content = file_get_contents('http://ift.tt/291UbjS');
$dom = new DOMDocument();
$dom->loadHtml($content);
$script = $dom->getElementsByTagName('script')[6]->textContent;
$script = preg_replace("/window._sharedData = /",'',$script);
$script = substr( $script, 0, -1 );

$script = json_decode($script);
$comments = $script->entry_data->PostPage[0]->media->comments->nodes;
?>
<div style="direction:rtl">
<?php
foreach($comments as $comment) :
        echo '<div>' . $comment->user->username . ':<br />' . $comment->text . '</div><br />';
endforeach;
?>
</div> 

But there is a problem: my code only shows some of the last comments. not all of them!

What should i do to get all of the comments of a post?

Remember, i do not want use an api! It's just a web scraping project.




Aucun commentaire:

Enregistrer un commentaire