from typing import List
from bs4 import BeautifulSoup


def parse_cross_listings(xlist_html: str) -> List[str]:
    """
    Retrieve cross-listings (CRN codes) from the HTML in the 'xlist' field from the Yale API.

    Note that the cross-listings do not include the course itself.

    Parameters
    ----------
    xlist_html:
        'xlist' field from the Yale API response.

    Returns
    -------
    xlist_crns:
        CRN codes of course cross-listings.
    """
    xlist_soup = BeautifulSoup(xlist_html, features="lxml")

    xlist_crns = xlist_soup.find_all("a", {"data-action": "result-detail"})
    xlist_crns = [x["data-key"] for x in xlist_crns]
    xlist_crns = [x[4:] for x in xlist_crns if x[:4] == "crn:"]

    return xlist_crns