1、通过接口登录获得cookie
def get_token_cookie(): test = SSO_EXAMPLE() token = test.get_session.json()['token'] cookie = test.get_session.cookies return token,cookie token,cookie = get_token_cookie() print(token) cookie_value = cookie.values()[0]
2、给selenium使用,绕开登录页面
options=webdriver.ChromeOptions() options.add_argument("ignore-certificate-errors") # 跳过“您的连接不是私密连接” options.add_experimental_option("excludeSwitches",['enable-automation']) # 跳过“正在受到自动测试软件的控制” driver = webdriver.Chrome(chrome_options=options) driver.get("https://%s" % server_ip) driver.maximize_window() time.sleep(10) # 登录部分 # driver.add_cookie({'domain': '20.68.129.194', 'httpOnly': True, 'name': 'session-sensor', 'path': '/', 'secure': True, 'value': '1fec23c5-7f5b-492d-be00-4ee0ad63d178'}) driver.add_cookie({'domain': '20.68.129.194', 'httpOnly': True, 'name': 'session-sensor', 'path': '/', 'secure': True, 'value': cookie_value}) driver.get("https://20.68.129.194/sensor/threat/alarm") # 不用再登录,可以直接打开页面
标签:登录,get,driver,selenium,token,api,cookie,options From: https://www.cnblogs.com/superbaby11/p/17844506.html