Hey everyone, I just wanted to show off what I've accomplished today because I'm really proud of how it came together, and I hope to inspire others.
I've added a 100% custom top list rank widget to my forums at Salvage RSPS: Top Runescape Private Server 2017.
Here's a preview:
I started by making a simple website scraper using simple html dom. I define my server name, the top list name and url (url of the page):
Code:
$rune_server = "Rune-Server";
$rune_server_url = "https://www.rune-server.ee/toplist-";
$name_of_server = "salvage";
I then scrape, page by page for my server name in lower case:
Code:
$rune_server_rank = null;
for ($i = 1; $i <= $PAGE_SEARCH_MAX; $i++) {
$rune_server_rank = getRuneServerRank($name_of_server, file_get_html($rune_server_url . $i));
if ($rune_server_rank != null) {
break;
}
}
The scraping is as follows:
Code:
function getRuneServerRank($server, $html) {
$trs = $html->find("table tbody tr"); //the dom of the individual rows in the top list
foreach ($trs as $tr) {
if (strpos(strtolower($tr), $server)) { //try to find my server name in one of the rows
//server found (table row)
$tds = $tr->find("td font"); //the nearest wrapper of the rank number I wish to find
foreach ($tds as $td) {
//found cell with rank
$rank = $td->plaintext; //get the plain text number from the tag
return (int) $rank; //convert it to an int and return
}
}
}
return null;
}
I do the same for all the top lists I have my server listed on and add them to an array, then iterate through the array adding each find to a database table with the name of the top list, rank, a link, and the date it was inserted (I update if it the name and date already exist).
On my website, I'm using Invision Power Board and I've added the TXT & PHP Widget to my add-ons. I dragged one of the php blocks onto my homepage and added a bit of code in the block to retrieve the data from the database and display it in a way I saw fit.
Next, I added my php class that updates the database to my hosting site and set it to run as a cron job every 10 minutes.
That's it! I left out a few parts just so this isn't a direct copy-paste, but it's very doable. The hardest part is figuring out the dom, but once you figure out and understand one site, the rest will come very easily. Leave any questions or comments you may have down below.