daily pastebin goal
21%
SHARE
TWEET

php скрипт выводит id пользователей и текст постов по ГЕО

a guest Aug 29th, 2017 456 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. //переменные
  4. $url_parser="https://www.instagram.com/explore/locations/734660749/kamelya-collection-exclusive-hotels/"; //ссылка для парсинга
  5. $glubina_stranic="1"; //глубина парсинга, на одной странице 20 id пользователей
  6.  
  7. class instaWrapper {
  8. static function getFeedByUrl($url) {
  9. $source = file_get_contents($url);
  10. if ($source == false) {
  11. echo "Connection problem";
  12. die();
  13. }
  14. $shards = explode('window._sharedData = ', $source);
  15. $insta_json = explode(';</script>', $shards[1]);
  16. $insta_array = json_decode($insta_json[0], TRUE);
  17. if (isset($insta_array['entry_data']['ProfilePage']))
  18. $nodes = $insta_array['entry_data']['ProfilePage'][0]['user']['media']['nodes'];
  19. elseif (isset($insta_array['entry_data']['LocationsPage']))
  20. $nodes = $insta_array['entry_data']['LocationsPage'][0]['location']['media']['nodes'];
  21. elseif (isset($insta_array['entry_data']['TagPage']))
  22. $nodes = $insta_array['entry_data']['TagPage'][0]['tag']['media']['nodes'];
  23. $result=[];
  24. foreach($nodes as $item) {
  25. $result[]=[
  26. "id" => $item['id'],
  27. "code" => $item['code'],
  28. "url" => "https://www.instagram.com/p/".$item['code'],
  29. "timestamp" => $item['date'],
  30. "date" => date("d.m.Y H:i:s", $item['date']),
  31. "caption" => (isset($item['caption'])?$item['caption']:false),
  32. "owner_id" => $item['owner']['id'],
  33. "thumbnail_src" => $item['thumbnail_src'],
  34. "image_src" => $item['display_src'],
  35. "is_video" => (boolean)$item['is_video'],
  36. "dimensions" => $item['dimensions']
  37. ];
  38. }
  39. return $result;
  40. }
  41. }
  42.  
  43. $insta_massiv = (
  44. instaWrapper::getFeedByUrl("$url_parser")
  45. );
  46. for ($i = 1; $i < count($insta_massiv); $i++)
  47. {
  48. echo $insta_massiv[$i]['owner_id']." - ";
  49. echo $insta_massiv[$i]['caption']."<br>";    
  50. $last_id_anketa = $insta_massiv[$i]['id'];
  51. }
  52. $x=0;
  53. while ($x++<$glubina_stranic)
  54. {
  55. $insta_massiv = (
  56. instaWrapper::getFeedByUrl("$url_parser?max_id=$last_id_anketa")
  57. );
  58. for ($i = 1; $i < count($insta_massiv); $i++)
  59. {
  60. echo $insta_massiv[$i]['owner_id']." - ";
  61. echo $insta_massiv[$i]['caption']."<br>";
  62. $last_id_anketa = $insta_massiv[$i]['id'];
  63. }
  64. }
  65. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top