B
B
Bjornie2017-01-18 03:31:55
Parsing
Bjornie, 2017-01-18 03:31:55

Parse instagram accounts by location?

The question is about parsing profile descriptions, which I don't think should be a problem. However, the question is: is it possible to parse based on the user's location? For example a city. It seems that Instagram does not have such a function as filling in the country / city ...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
2
2gaap, 2017-04-13
@Bjornie

I found such an example on php
php code works fine on phpfiddle.org

<?php

//переменные
$url_parser="https://www.instagram.com/explore/locations/123456/"; //ссылка для парсинга
$glubina_stranic="10"; //глубина парсинга, на одной странице 20 id пользователей

class instaWrapper {
static function getFeedByUrl($url) {
$source = file_get_contents($url);
if ($source == false) {
echo "Connection problem";
die();
}
$shards = explode('window._sharedData = ', $source);
$insta_json = explode(';</script>', $shards[1]);
$insta_array = json_decode($insta_json[0], TRUE);
if (isset($insta_array['entry_data']['ProfilePage']))
$nodes = $insta_array['entry_data']['ProfilePage'][0]['user']['media']['nodes'];
elseif (isset($insta_array['entry_data']['LocationsPage']))
$nodes = $insta_array['entry_data']['LocationsPage'][0]['location']['media']['nodes'];
elseif (isset($insta_array['entry_data']['TagPage']))
$nodes = $insta_array['entry_data']['TagPage'][0]['tag']['media']['nodes'];
$result=[];
foreach($nodes as $item) {
$result[]=[
"id" => $item['id'],
"code" => $item['code'],
"url" => "https://www.instagram.com/p/".$item['code'],
"timestamp" => $item['date'],
"date" => date("d.m.Y H:i:s", $item['date']),
"caption" => (isset($item['caption'])?$item['caption']:false),
"owner_id" => $item['owner']['id'],
"thumbnail_src" => $item['thumbnail_src'],
"image_src" => $item['display_src'],
"is_video" => (boolean)$item['is_video'],
"dimensions" => $item['dimensions']
];
}
return $result;
}
}

$insta_massiv = (
instaWrapper::getFeedByUrl("$url_parser")
);
for ($i = 1; $i < count($insta_massiv); $i++) 
{ 
echo $insta_massiv[$i]['owner_id']."<br>";
$last_id_anketa = $insta_massiv[$i]['id']; 
}
$x=0;
while ($x++<$glubina_stranic) 
{
$insta_massiv = (
instaWrapper::getFeedByUrl("$url_parser?max_id=$last_id_anketa")
); 
for ($i = 1; $i < count($insta_massiv); $i++) 
{ 
echo $insta_massiv[$i]['owner_id']."<br>";
$last_id_anketa = $insta_massiv[$i]['id']; 
}
}
?>

Source: www.bubasik.com/php-parser-in...m-po-geometke
The script has only 2 parameters:
- Link for parsing, you can get it by going to the instagram website, enter the address or your city and get a link in the address browser line
- Parsing depth, the number to which page to collect user ids.
Added:
Changed slightly the script - now it displays the text of the posts. The code is here - https://pastebin.com/0SRAMPMs
You can also run the code online on the service - phpfiddle.org

A
azShoo, 2017-01-18
@azShoo

Not users are attached to the image, but Media. Geotags and that's it. But, keep in mind that the image can fast without them.
https://www.instagram.com/developer/endpoints/loca...

I
Ilnur Akhunov, 2017-01-19
@akhunovilnur

Gathering an audience by geotags. Yes it is possible.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question