Skip to content

Instantly share code, notes, and snippets.

@tschoffelen
Created March 31, 2018 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tschoffelen/000e3ec9f0cf592901ef0fbd13a3a6fd to your computer and use it in GitHub Desktop.
Save tschoffelen/000e3ec9f0cf592901ef0fbd13a3a6fd to your computer and use it in GitHub Desktop.
<?php
// Set username
$username = 'tschoffelen';
// Get page contents
$content = file_get_contents('https://dribbble.com/' . $username . '?page=1&per_page=12');
// Parse page content into $shots array
$shots = [];
$meta = [];
$matches = [];
preg_match_all('#<img alt="[^"]+" src="([^"]+)" />\s+</picture>\s+</a>\s+<a class="dribbble-over" href="([^"]+)">\s+<strong>([^<]+)</strong>#i', $content, $matches, PREG_SET_ORDER);
preg_match('#<script>\s+var newestShots = (\[[^;]+)#i', $content, $json);
$json = preg_replace('#\s(\w+):#i', '"$1":', $json[1]);
$json = preg_replace('#("published_at":)\s\'([^\']+)\'#i', '$1"$2"', $json);
$json = json_decode($json, true);
foreach ($json as $shot) {
$meta[$shot['path']] = $shot;
}
foreach ($matches as $match) {
$shot_meta = @$meta[$match[2]] ?: [];
$shots[] = array_merge($shot_meta, [
'image' => $match[1],
'url' => 'https://dribbble.com' . $match[2],
'title' => $match[3]
]);
}
// Output shots array
echo json_encode($shots, JSON_PRETTY_PRINT);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment