import requests
import re
from bs4 import BeautifulSoup


def get_soup(fbref_url, name=None):
    """ Get soup of FBRef URL

    Parameters
    ----------
    fbref_url : str
        Url of FBRef. Can either be the search url or an exact match url
    name : str
        Name to search for, must be used with the search url.
    """
    if name:
        fbref_url += "=" + name
    response = requests.get(fbref_url)
    comm = re.compile("<!--|-->")
    soup = BeautifulSoup(comm.sub("", response.text), "lxml")

    return soup