Created
July 6, 2011 10:49
-
-
Save ashleydw/1066993 to your computer and use it in GitHub Desktop.
Scrape SongKick venue page for events with Zend Framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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