1. 获取cookies
实现代码如下:
import time from selenium import webdriver class cookies_login: wd=webdriver.Chrome() def getCookies(self): wd=self.wd wd.maximize_window() #登录成功跳转后的页面 url = "http://47.108.47.47:81/admin" #登录页面 wd.get("http://47.108.47.47:81/admin/login?company=9") while True: print("please login") time.sleep(3) while wd.current_url == url: cookies=wd.get_cookies() wd.quit() return cookies
2. 绕过验证码登录
实现代码如下:
from selenium import webdriver import time from xctest_selenium.get_cookies import * class NoSignLogin: def get_nosignlogin(self): cookies=cookies_login().getCookies() wd=webdriver.Chrome() wd.maximize_window() wd.implicitly_wait(20) # 登录成功跳转后的页面 wd.get("http://47.108.74.74:81/admin#datacount") for cookie in cookies: wd.add_cookie(cookie) time.sleep(3) wd.refresh()