Created
July 18, 2010 15:20
-
-
Save dtinth/480475 to your computer and use it in GitHub Desktop.
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
Array | |
( | |
[0] => Array | |
( | |
[index] => 1 | |
[name] => BATT | |
[level] => Futurist | |
) | |
[1] => Array | |
( | |
[index] => 2 | |
[name] => SPEEDSON | |
[level] => Vanquisher | |
) | |
[2] => Array | |
( | |
[index] => 3 | |
[name] => HUCKERBY | |
[level] => Vanquisher | |
) | |
[3] => Array | |
( | |
[index] => 4 | |
[name] => CHOPANG | |
[level] => DJMAX Grand Master | |
) | |
[4] => Array | |
( | |
[index] => 5 | |
[name] => LINGNUN | |
[level] => DJMAX Grand Master | |
) | |
[5] => Array | |
( | |
[index] => 6 | |
[name] => DANTE | |
[level] => Would Famous | |
) | |
[6] => Array | |
( | |
[index] => 7 | |
[name] => I2EBIRTH | |
[level] => Would Famous | |
) | |
[7] => Array | |
( | |
[index] => 8 | |
[name] => SKY! | |
[level] => Would Famous | |
) | |
[8] => Array | |
( | |
[index] => 9 | |
[name] => LSLINGER | |
[level] => Would Famous | |
) | |
[9] => Array | |
( | |
[index] => 10 | |
[name] => MORMINZ | |
[level] => Superstar | |
) | |
[10] => Array | |
( | |
[index] => 11 | |
[name] => MATOOM | |
[level] => Superstar | |
) | |
[11] => Array | |
( | |
[index] => 12 | |
[name] => FISHER | |
[level] => Superstar | |
) | |
[12] => Array | |
( | |
[index] => 13 | |
[name] => FROSTY | |
[level] => Show Stopper | |
) | |
[13] => Array | |
( | |
[index] => 14 | |
[name] => HOUSE | |
[level] => Show Stopper | |
) | |
[14] => Array | |
( | |
[index] => 15 | |
[name] => OHMZA | |
[level] => Hit Maker | |
) | |
) |
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 | |
function parse_document($doc, $selectors) { | |
$output = array(); | |
foreach ($selectors as $name => $selector) { | |
foreach ($doc->find($selector[0]) as $k => $v) { | |
if (!isset($output[$k])) { | |
$output[$k] = array(); | |
} | |
$output[$k][$name] = call_user_func($selector[1], pq($v)); | |
} | |
} | |
return $output; | |
} |
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 | |
include 'phpQuery/phpQuery/phpQuery.php'; | |
include 'parsedoc.php'; | |
$titleNames = array( | |
'NOOB!', 'Beginner', 'Trainee', 'Amateur', 'Rookie', 'Sub DJ', 'Middle Man', 'Main DJ', | |
'Pop DJ', 'High Class', 'Professional', 'Mix Master', 'Trendsetter', 'Hit Maker', | |
'Show Stopper', 'Superstar', 'Would Famous', 'DJMAX Grand Master', 'Vanquisher', | |
'Futurist', '???' | |
); | |
class PCParser { | |
function parseNumber($x) { | |
return intval(preg_replace('~[^0-9]~', '', $x->text())); | |
} | |
function parseName($x) { | |
return $x->text(); | |
} | |
function parseLevel($x) { | |
global $titleNames; | |
if (preg_match('~lev-(\d+)~i', $x->attr('src'), $m)) | |
return $titleNames[intval($m[1])]; | |
return $titleNames[$m[0]]; | |
} | |
} | |
$page = phpQuery::newDocumentFileHTML('http://www.djmax.in.th/technika/rankDJTitle.asp'); | |
$spec = array( | |
'index' => array('.b12:nth-child(1)', array('PCParser', 'parseNumber')), | |
'name' => array('td td td td td td td td .b12', array('PCParser', 'parseName')), | |
'level' => array('td td td td td td td td:nth-child(3) .png24', array('PCParser', 'parseLevel')), | |
); | |
echo '<pre>'; | |
print_r (parse_document($page, $spec)); | |
echo '</pre>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment