Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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
You can’t perform that action at this time.