from bs4 import BeautifulSoup


def get_script_by_id(source_html:str, script_id:int):
    """
    This function finds a script in a specific index in the page source html.

    @param source_html: The source html of the page in which we want to find the script tag.
    @type source_html: str
    @param script_id: The id of the script tag (it's index from the top).
    @type script_id: int
    @return: The script tag of the correct index or None if script was not found.
    @rtype: Tag
    """
    soup = BeautifulSoup(source_html, "html.parser")
    all_scripts = soup.find_all("script")
    if script_id > -1 and script_id < len(all_scripts):
        return all_scripts[script_id]
    else:
        return None