def login(driver, username, password, failed=0):
    if (failed == 3):
        raise Exception('门户登录失败')
    iaaaUrl = 'https://iaaa.pku.edu.cn/iaaa/oauth.jsp'
    appName = quote('北京大学校内信息门户新版')
    redirectUrl = 'https://portal.pku.edu.cn/portal2017/ssoLogin.do'
    driver.get('https://portal.pku.edu.cn/portal2017/')
    driver.get(f'{iaaaUrl}?appID=portal2017&appName={appName}&redirectUrl={redirectUrl}')
    print('门户登陆中...')
    driver.find_element_by_id('user_name').send_keys(username)
    time.sleep(TIMESLP)
    driver.find_element_by_id('password').send_keys(password)
    time.sleep(TIMESLP)
    driver.find_element_by_id('logon_button').click()
    try:
        WebDriverWait(driver, TIMEOUT).until(EC.visibility_of_element_located((By.LINK_TEXT, '我知道了')))
    except:
        pass
    else:
        driver.find_element_by_link_text('我知道了').click()
    try:
        WebDriverWait(driver, TIMEOUT).until(EC.visibility_of_element_located((By.ID, 'all')))
    except:
        login(driver, username, password, (failed + 1))
    else:
        print('门户登录成功！')
def login(driver, username, password, failed=0):
    if (failed == 3):
        raise Exception('门户登录失败')
    iaaaUrl = 'https://iaaa.pku.edu.cn/iaaa/oauth.jsp'
    appName = quote('北京大学校内信息门户新版')
    redirectUrl = 'https://portal.pku.edu.cn/portal2017/ssoLogin.do'
    driver.get('https://portal.pku.edu.cn/portal2017/')
    driver.get(f'{iaaaUrl}?appID=portal2017&appName={appName}&redirectUrl={redirectUrl}')
    print('门户登陆中...')
    driver.find_element_by_id('user_name').send_keys(username)
    time.sleep(TIMESLP)
    driver.find_element_by_id('password').send_keys(password)
    time.sleep(TIMESLP)
    driver.find_element_by_id('logon_button').click()
    try:
        WebDriverWait(driver, TIMEOUT).until(EC.visibility_of_element_located((By.LINK_TEXT, '我知道了')))
    except:
        pass
    else:
        driver.find_element_by_link_text('我知道了').click()
    try:
        WebDriverWait(driver, TIMEOUT).until(EC.visibility_of_element_located((By.ID, 'all')))
    except:
        login(driver, username, password, (failed + 1))
    else:
        print('门户登录成功！')