Question

I am currently doing some work for a client which happens to be a video game group for the game World of Warcraft.

They want to show their current rating on their website.

The ratings are shown here.

They would like to have the number for 'Oceanic', and the number for 'US' displayed on their website.

Is anyone able to show me a way that I can have those numbers automatically update on the website should they change?

Thanks!

Was it helpful?

Solution

You can use this snippet to scrap the data - assuming PHP is okay since you're running wordpress. I'd save these values in a database/flatline/cache.

<?php

$data = file_get_contents('http://www.wowprogress.com/guild/us/caelestrasz/Crimson/rating.tier13_25');

$oceanic = explode('<dt>Oceanic: </dt>', $data);
$oceanic = substr($oceanic[1], 4, strpos($oceanic[1], '</dd>') - 4);

$us = explode('<dt>US: </dt>', $data);
$us = substr($us[1], 4, strpos($us[1], '</dd>') - 4);

echo 'Oceanic: ' . $oceanic . "<br />\n";
echo 'US: ' . $us . "<br />\n";

OTHER TIPS

It's quite easy. I prefer using simplehtmldom, but you can also use the builtin php dom parsing methods.

require 'simple_html_dom.php';
$html = file_get_html('http://www.wowprogress.com/guild/us/caelestrasz/Crimson/rating.tier13_25');
$xxx = $html->find('div.guildStats dl dd');

foreach($xxx as $k)
echo $k->plaintext."\n";

Due to cross domain security you cannot do this with javascript, you will have to get your information server side if you have access to it.

Here's a solution with RegEx.

<?php

$data = implode('', file('http://www.wowprogress.com/guild/us/caelestrasz/Crimson/rating.tier13_25'));
$pat_world = '/<span class="rank blue">(\d+)<\/span>/';
$pat_us = '/<dt>US:\D+(\d+)/';

preg_match($pat_world, $data, $world);
preg_match($pat_us, $data, $us);

echo $world[1];
echo "\n\n";
echo $us[1];

I know everyone is anti-regex for web scraping, but I think it works just great in simple situations like this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top