@asyncio.coroutine
def get_highscores(server, category, pagenum, profession=0, tries=5):
    'Gets a specific page of the highscores\n    Each list element is a dictionary with the following keys: rank, name, value.\n    May return ERROR_NETWORK'
    url = url_highscores.format(server, category, profession, pagenum)
    try:
        page = (yield from aiohttp.get(url))
        content = (yield from page.text(encoding='ISO-8859-1'))
    except Exception:
        if (tries == 0):
            log.error("get_highscores: Couldn't fetch {0}, {1}, page {2}, network error.".format(server, category, pagenum))
            return ERROR_NETWORK
        else:
            tries -= 1
            (yield from asyncio.sleep(network_retry_delay))
            ret = (yield from get_highscores(server, category, pagenum, profession, tries))
            return ret
    try:
        start_index = content.index('<td style="width: 20%;" >Vocation</td>')
        end_index = content.index('<div style="float: left;"><b>&raquo; Pages:')
        content = content[start_index:end_index]
    except ValueError:
        if (tries == 0):
            log.error("get_highscores: Couldn't fetch {0}, {1}, page {2}, network error.".format(server, category, pagenum))
            return ERROR_NETWORK
        else:
            tries -= 1
            (yield from asyncio.sleep(network_retry_delay))
            ret = (yield from get_highscores(server, category, pagenum, profession, tries))
            return ret
    if (category == 'loyalty'):
        regex_deaths = '<td>([^<]+)</TD><td><a href="https://secure.tibia.com/community/\\?subtopic=characters&name=[^"]+" >([^<]+)</a></td><td>[^<]+</TD><td>[^<]+</TD><td style="text-align: right;" >([^<]+)</TD></TR>'
        pattern = re.compile(regex_deaths, (re.MULTILINE + re.S))
        matches = re.findall(pattern, content)
        scoreList = []
        for m in matches:
            scoreList.append({'rank': m[0], 'name': m[1], 'value': m[2].replace(',', '')})
    else:
        regex_deaths = '<td>([^<]+)</TD><td><a href="https://secure.tibia.com/community/\\?subtopic=characters&name=[^"]+" >([^<]+)</a></td><td>[^<]+</TD><td style="text-align: right;" >([^<]+)</TD></TR>'
        pattern = re.compile(regex_deaths, (re.MULTILINE + re.S))
        matches = re.findall(pattern, content)
        scoreList = []
        for m in matches:
            scoreList.append({'rank': m[0], 'name': m[1], 'value': m[2].replace(',', '')})
    return scoreList
Gets a specific page of the highscores
Each list element is a dictionary with the following keys: rank, name, value.
May return ERROR_NETWORK
@asyncio.coroutine
def get_highscores(server, category, pagenum, profession=0, tries=5):
    'Gets a specific page of the highscores\n    Each list element is a dictionary with the following keys: rank, name, value.\n    May return ERROR_NETWORK'
    url = url_highscores.format(server, category, profession, pagenum)
    try:
        page = (yield from aiohttp.get(url))
        content = (yield from page.text(encoding='ISO-8859-1'))
    except Exception:
        if (tries == 0):
            log.error("get_highscores: Couldn't fetch {0}, {1}, page {2}, network error.".format(server, category, pagenum))
            return ERROR_NETWORK
        else:
            tries -= 1
            (yield from asyncio.sleep(network_retry_delay))
            ret = (yield from get_highscores(server, category, pagenum, profession, tries))
            return ret
    try:
        start_index = content.index('<td style="width: 20%;" >Vocation</td>')
        end_index = content.index('<div style="float: left;"><b>&raquo; Pages:')
        content = content[start_index:end_index]
    except ValueError:
        if (tries == 0):
            log.error("get_highscores: Couldn't fetch {0}, {1}, page {2}, network error.".format(server, category, pagenum))
            return ERROR_NETWORK
        else:
            tries -= 1
            (yield from asyncio.sleep(network_retry_delay))
            ret = (yield from get_highscores(server, category, pagenum, profession, tries))
            return ret
    if (category == 'loyalty'):
        regex_deaths = '<td>([^<]+)</TD><td><a href="https://secure.tibia.com/community/\\?subtopic=characters&name=[^"]+" >([^<]+)</a></td><td>[^<]+</TD><td>[^<]+</TD><td style="text-align: right;" >([^<]+)</TD></TR>'
        pattern = re.compile(regex_deaths, (re.MULTILINE + re.S))
        matches = re.findall(pattern, content)
        scoreList = []
        for m in matches:
            scoreList.append({'rank': m[0], 'name': m[1], 'value': m[2].replace(',', )})
    else:
        regex_deaths = '<td>([^<]+)</TD><td><a href="https://secure.tibia.com/community/\\?subtopic=characters&name=[^"]+" >([^<]+)</a></td><td>[^<]+</TD><td style="text-align: right;" >([^<]+)</TD></TR>'
        pattern = re.compile(regex_deaths, (re.MULTILINE + re.S))
        matches = re.findall(pattern, content)
        scoreList = []
        for m in matches:
            scoreList.append({'rank': m[0], 'name': m[1], 'value': m[2].replace(',', )})
    return scoreList