Easily way is request with ?__a=1
like https://www.instagram.com/explore/tags/girls/?__a=1
and receive JSON without parsing HTML and window._sharedData =
In json you can see page_info scope with end_cursor:
"page_info": {
"has_previous_page": false,
"start_cursor": "1381007800712523480",
"end_cursor": "J0HWCVx1AAAAF0HWCVxxQAAAFiYA",
"has_next_page": true
},
use end_cursor to request next portion of images:
https://www.instagram.com/explore/tags/girls/?__a=1&max_id=J0HWCVx1AAAAF0HWCVxxQAAAFiYA
UPD:
<?php
$baseUrl = 'https://www.instagram.com/explore/tags/girls/?__a=1';
$url = $baseUrl;
while(1) {
$json = json_decode(file_get_contents($url));
print_r($json->tag->media->nodes);
if(!$json->tag->media->page_info->has_next_page) break;
$url = $baseUrl.'&max_id='.$json->tag->media->page_info->end_cursor;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…