import requests
from bs4 import BeautifulSoup


def get_nbp_league_soup(league):
    """NPBのリーグ毎の表を取得する関数
        e.g. https://www.baseball-reference.com/register/league.cgi?code={league}&class=Fgn
    
        Args:
            league(str): セリーグ or パリーグ (JPCL or JPPL)
            
        Return:
            soup: リーグの一覧表
    """
    
    leagues_list = ['JPCL', 'JPPL']
    
    if not league in leagues_list:
        raise ValueError(f'Valid league are {leagues_list}')
    
    url = f'https://www.baseball-reference.com/register/league.cgi?code={league}&class=Fgn'
    s = requests.get(url).content
    return BeautifulSoup(s, "lxml")