<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _find_rtd_version():
 """Find closest RTD doc version."""

    vstr = 'latest'
    try:
        import ginga
        from bs4 import BeautifulSoup
    except ImportError:
        return vstr

    # No active doc build before this release, just use latest.
    if not minversion(ginga, '2.6.0'):
        return vstr

    # Get RTD download listing.
    url = 'https://readthedocs.org/projects/ginga/downloads/'
    with urllib.request.urlopen(url) as r:
        soup = BeautifulSoup(r, 'html.parser')

    # Compile a list of available HTML doc versions for download.
    all_rtd_vernums = []
    for link in soup.find_all('a'):
        href = link.get('href')
        if 'htmlzip' not in href:
            continue
        s = href.split('/')[-2]
        if s.startswith('v'):  # Ignore latest and stable
            all_rtd_vernums.append(s)
    all_rtd_vernums.sort(reverse=True)

    # Find closest match.
    ginga_ver = ginga.__version__
    for rtd_ver in all_rtd_vernums:
        if ginga_ver > rtd_ver[1:]:  # Ignore "v" in comparison
            break
        else:
            vstr = rtd_ver

    return vstr