Skip to content

Instantly share code, notes, and snippets.

@jackmcdade
Last active February 2, 2021 09:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackmcdade/ff8bf61fb57db5e74edd8a7b9b5a2b26 to your computer and use it in GitHub Desktop.
Save jackmcdade/ff8bf61fb57db5e74edd8a7b9b5a2b26 to your computer and use it in GitHub Desktop.
Instagrizzle Scraper
// Quick and dirty Instagram scraper
private function scrape($username)
{
$source = file_get_contents('http://instagram.com/' . $username);
$shards = explode('window._sharedData = ', $source);
$json_response = explode(';</script>', $shards[1]);
$response_array = json_decode($json_response[0], TRUE);
$nodes = array_get($response_array, 'entry_data:ProfilePage:0:user:media:nodes');
$data = array();
foreach ($nodes as $node) {
$url = 'https://instagram.com/p/' . $node['code'];
$image = $node['display_src'];
$data[] = $node + [
'url' => $url,
'link' => $url,
'image' => $image,
'thumbnail' => $node['thumbnail_src'],
'images' => [
'high_resolution' => ['url' => $image],
'low_resolution' => ['url' => $image]
]
];
}
return $data;
}
function array_get($array, $key, $default = null)
{
if (is_null($key)) return $array;
if (isset($array[$key])) return $array[$key];
foreach (explode('.', $key) as $segment)
{
if ( ! is_array($array) || ! array_key_exists($segment, $array))
{
return value($default);
}
$array = $array[$segment];
}
return $array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment