def clean_result_page(resultpage):
    """
    Takes the HTML output from the TMHMM result page and trims some HTML
    to make the output parsable by the existing standalone tmhmm parser.

    Returns the cleaned up result page.
    """
    resultlines = resultpage.split('\n')
    firstpreindex = 0
    for i in range(len(resultlines)):
        if '<pre>' in resultlines[i]:
            firstpreindex = i
            break
    resultpage = '\n'.join(resultlines[firstpreindex:-3])
    resultpage = resultpage.replace('<hr>', '\n')
    resultpage = resultpage.replace('<P>', '')
    resultpage = resultpage.replace('<pre>', '')
    resultpage = resultpage.replace('</pre>', '')
    return resultpage
