Created
August 30, 2013 15:46
-
-
Save solocommand/6391206 to your computer and use it in GitHub Desktop.
Battle.net Armory Scraper
This file contains 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
function armory_scrape($realm, $character) | |
{ // Scrape armory url based on provided realm and character information | |
$realm = sanitize_xml(strtolower($realm)); | |
$character = sanitize_xml(strtolower($character)); | |
$armoryurl = "http://us.battle.net/wow/en/character/$realm/$character/advanced"; | |
$debug = false; | |
function scrape($armoryurl) | |
{ // Get Armory Page | |
if($content=@file_get_contents($armoryurl)) | |
{ | |
return $content; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
function process_page($content) | |
{ // Process Armory Data | |
/* eminence.character_cache structure: | |
SELECT `id`, `realm`, `name`, `account`, `lastupdate`, `lastcache`, `title`, `guild`, `level`, `race`, `spec`, | |
`class`, `points`, `ilvl`, `health`, `power`, `tradeskill1_name`, `tradeskill1_value`, `tradeskill2_name`, | |
`tradeskill2_value`, `inv01`, `inv02`, `inv03`, `inv04`, `inv05`, `inv06`, `inv07`, `inv08`, `inv09`, `inv10`, | |
`inv11`, `inv12`, `inv13`, `inv14`, `inv15`, `inv16`, `inv17`, `inv18`, `inv19` FROM `character_cache` WHERE 1; | |
*/ | |
$content_array = array(); | |
// Realm[1] and Character Name[2] | |
$tempcrap = explode("/", substr($content, strpos($content, '<div class="name"><a href="/wow/en/character/')+45, 20)); | |
$realm = $tempcrap[0]; | |
$name = $tempcrap[1]; | |
// Account[3] Get ID from PHP if logged in...I'm too lazy to code this crap now, I'll do it later. | |
# | |
// lastupdate[4] | |
$tempcrap = explode("<", substr($content, strpos($content, '<div class="summary-lastupdate">')+58, 30)); | |
$lastupdate = ltrim(rtrim($tempcrap[0])); | |
// | |
$content_array[0] = NULL; # id | |
$content_array[1] = $realm; # realm | |
$content_array[2] = $name; # name | |
$content_array[3] = NULL; # account | |
$content_array[4] = $lastupdate; # lastupdate | |
if(strstr($content, "<p>This character profile could not be displayed, possibly for one of the following reasons:</p>")) | |
{ return 1; } | |
else | |
{ return $content_array; } | |
} | |
function update_cache($content_array) | |
{ // Update SQL Cache | |
} | |
// DEBUG | |
if($debug) { echo "<a href=\"$armoryurl\" target=\"_blank\">$armoryurl</a><br /><br />"; } | |
if(!$content = scrape($armoryurl)) | |
{ | |
if($debug) { echo "Scrape failed."; } | |
return false; | |
} | |
else | |
{ | |
$content_array = process_page($content); | |
if($debug) | |
{ | |
echo "Scrape Succeded.<br /><br />"; | |
echo "<pre>"; | |
var_dump($content_array); | |
echo "</pre>"; | |
echo "<div style=\"border:1px solid;\">" . $content . "</div>"; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment