Skip to content

Instantly share code, notes, and snippets.

@ashleydw
Created July 6, 2011 10:49
Show Gist options
  • Save ashleydw/1066993 to your computer and use it in GitHub Desktop.
Save ashleydw/1066993 to your computer and use it in GitHub Desktop.
Scrape SongKick venue page for events with Zend Framework
<?php
/**
* @version 1
* @author Ashley White, http://www.needathinkle.com/
* @license http://creativecommons.org/licenses/by-sa/3.0/
*/
final class Thinkle_Service_SongKick_Venue {
const VENUE_URI = 'http://www.songkick.com/venues/%d/calendar';
public static function getCalendar() {
$id = ''; //Put your ID here. You should put caching on this below
$events = array();
$client = new Zend_Http_Client(sprintf(self::VENUE_URI, $id));
$response = $client->request();
$date = false;
if($response->isSuccessful()) {
$html = $response->getBody();
$doc = new DOMDocument;
@$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
foreach($xpath->query('//ol[@class="gigography results"]/li') as $li) {
if($li->getAttribute('class') == 'date') {
$date = date('Y-m-d', strtotime(trim($li->textContent)));
$events[$date] = array();
} else {
if(!$date)
continue;
$e = array();
$newDom = new DOMDocument;
$newDom->appendChild($newDom->importNode($li, true));
$xpath = new DOMXPath($newDom);
$e['link'] = 'http://www.songkick.com'.$xpath->query('//div[@class="summary"]/a')->item(0)->getAttribute('href');
$e['headliners'] = $xpath->query('//div[@class="summary"]/a/span')->item(0)->textContent;
$venueLink = $xpath->query('//div[@class="location vcard"]/span[@class="adr"]/a');
$e['location'] = $venueLink->item(0)->getAttribute('href');
$e['venue'] = $venueLink->item(0)->textContent;
$events[$date][] = $e;
}
}
}
return $events;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment