Independent latest loot table function (Scraping)

Interested contributing to WebDKP? Find the latest development progress here.

Posts: 2
Joined: Fri Apr 16, 2010 11:43 am
PostPosted: Fri Apr 16, 2010 12:02 pm

I don't know if this particular function has been posted before or not but I have just created it for my guild & it works v.nicely :). This is a neat little function which scrapes data from the loot page of your guilds page on the site, returning the latest items looted.

You can view it working here:

Although this is a 'template' site it will work on any site (provided your site is running PHP). Once ran, the function will return a basic HTML table with all the necessary "Powered by" scripts included. There is no need to include them elsewhere on your page.

Example usage of this function:

Code: Select all
_scrapeLoot("Agamaggan","Casual Hardcore",5)

1st param: $realmName = Your realm name, case-sensitive
2nd param: $guildName = Your guild name, case-sensitive
3rd param: $amount = Amount of latest loot you want, 5 = 5 results shown

Code below:

Code: Select all

   Scrapes data from loot page
   returning a list of x amount of latest loot & costs
   function _scrapeLoot($realmName,$guildName,$amount)
      //construct query
      $query = "" . $realmName . "/" . str_replace(" ","+",$guildName) . "/Loot";
      //include the wowhead item script within the calling page
      echo "<script src=\"\" type=\"text/javascript\"></script>";
      //run get_contents & save results
      $scrape = file_get_contents($query);
      //match and scrape our data
      $regex = "^item=(.+?)' class='(.+?)'>(.+?),\"id\":\"(.+?)\",\"points\":\"(.+?)\",\"player\":\"(.+?)\",\"date\":\"(.+?)\",\"datestring\":\"(.+?)\"^";
      /**construct a new array in an enclosing array to create more
      structured data */
      $results = array();
      //loop through and create array
         $results[sizeof($results)] = array($match[1][$i],$match[2][$i],str_replace("<\/a>\"","",$match[3][$i]),$match[5][$i],$match[6][$i],$match[8][$i]);
         Item ID: $match[1][$i]
         Quality: $match[2][$i]
         Item Name: str_replace("<\/a>\"","",$match[3][$i])
         Cost: $match[5][$i]
         Looted By: $match[6][$i]
      $strucTable = _constructTable($results);
      return $strucTable;
   function _constructTable($loot)
      //error check
      if(!is_array($loot)) die("Incorrect Usage. Expecting Array.");
      $table = "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">";
      //loop through and add loot
      foreach($loot as $n)
         $table .= "<tr><td>";
            //add cell contents
            $table .= "<font size=\"2\"><b><a href=\"". $n[0] ."\" class=\"" . $n[1] . "\">[" . $n[2] . "]</a></b></font><br>";
            //$table .= " <font size=\"2\">Looted By: " . $n[4] . " (Cost: " . ($n[3]*-1) . ")</font>";
            //create custom mouseover
            $table .= ' <font size="1"><a href="javascript:;" onmouseover="$WowheadPower.showTooltip(event, \'Looted&nbsp;By:&nbsp;<i>'. $n[4] . '</i><br>DKP&nbsp;Cost:&nbsp;<i>' . ($n[3]*-1) . '</i><br>Looted:&nbsp;<i>' . str_replace(" ","&nbsp;",$n[5]) . '</i>\', \'INV_Misc_Note_01\')" onmousemove="$WowheadPower.moveTooltip(event)"
                     onmouseout="$WowheadPower.hideTooltip();">' . $n[4] . '</a></font>';

         $table .= "</td></tr>";
      $table .= "</table>";
      return $table;


This function was written pretty quickly n im sure its not the most efficient way to do it or w.e but feel free to modify it etc. to suit your purposes :)

This is the first function ive posted so dont be too mean if its bugged or not the best way to do things ^^. If you have any problems making it work etc. then feel free to post below.

Hope this helps[code]
User avatar
Site Admin
Posts: 636
Joined: Fri May 22, 2009 12:06 pm
Location: Bronzebeard Server
PostPosted: Fri Apr 16, 2010 1:26 pm
Hey Selif,

Cool Post,

I think there's more activity related to the webdkp self host at


Posts: 2
Joined: Fri Apr 16, 2010 11:43 am
PostPosted: Fri Apr 16, 2010 1:32 pm

Thanks for telling me, i'll post it there for people to use too :)

Posts: 6549
Joined: Wed May 01, 2019 8:13 pm
PostPosted: Fri May 31, 2019 5:21 pm

Return to Development

Who is online

Users browsing this forum: No registered users and 1 guest