-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
156 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,56 @@ | ||
import time | ||
import traceback | ||
|
||
from selenium.webdriver.common.by import By | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
from selenium.webdriver.support import expected_conditions as ec | ||
from rich import print | ||
|
||
|
||
class LoginHandler: | ||
def __init__(self, log, driver) -> None: | ||
self.log = log | ||
self.driver = driver | ||
|
||
def automaticLogIn(self, username, password): | ||
self.driver.get("https://lolesports.com/schedule") | ||
time.sleep(2) | ||
el = self.driver.find_element(by=By.CSS_SELECTOR, value="a[data-riotbar-link-id=login]") | ||
self.driver.execute_script("arguments[0].click();", el) | ||
self.log.info("登录中...") | ||
print("[yellow]登录中...") | ||
wait = WebDriverWait(self.driver, 20) | ||
usernameInput = wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, "input[name=username]"))) | ||
usernameInput.send_keys(username) | ||
passwordInput = wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, "input[name=password]"))) | ||
passwordInput.send_keys(password) | ||
submitButton = wait.until(ec.element_to_be_clickable((By.CSS_SELECTOR, "button[type=submit]"))) | ||
self.driver.execute_script("arguments[0].click();", submitButton) | ||
self.log.debug("账密 提交成功") | ||
print("[green]账密 提交成功") | ||
time.sleep(5) | ||
if len(self.driver.find_elements(by=By.CSS_SELECTOR, value="div.text__web-code")) > 0: | ||
self.insertTwoFactorCode() | ||
wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, "div.riotbar-summoner-name"))) | ||
try: | ||
self.driver.get("https://lolesports.com/schedule") | ||
time.sleep(2) | ||
loginButton = self.driver.find_element(by=By.CSS_SELECTOR, value="a[data-riotbar-link-id=login]") | ||
self.driver.execute_script("arguments[0].click();", loginButton) | ||
self.log.info("登录中...") | ||
print("[yellow]登录中...") | ||
time.sleep(3) | ||
wait = WebDriverWait(self.driver, 15) | ||
usernameInput = wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, "input[name=username]"))) | ||
usernameInput.send_keys(username) | ||
passwordInput = wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, "input[name=password]"))) | ||
passwordInput.send_keys(password) | ||
submitButton = wait.until(ec.element_to_be_clickable((By.CSS_SELECTOR, "button[type=submit]"))) | ||
self.driver.execute_script("arguments[0].click();", submitButton) | ||
self.log.debug("账密 提交成功") | ||
print("[green]账密 提交成功") | ||
time.sleep(5) | ||
if len(self.driver.find_elements(by=By.CSS_SELECTOR, value="div.text__web-code")) > 0: | ||
self.insertCode() | ||
wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, "div.riotbar-summoner-name"))) | ||
except Exception as e: | ||
traceback.print_exc() | ||
self.log.error(traceback.format_exc()) | ||
|
||
def insertTwoFactorCode(self): | ||
wait = WebDriverWait(self.driver, 20) | ||
authText = wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, "h5.grid-panel__subtitle"))) | ||
self.log.info(f'请输入二级验证代码 ({authText.text})') | ||
print(f'[yellow]请输入二级验证代码 ({authText.text}') | ||
code = input('二级验证代码: ') | ||
codeInput = wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, "div.codefield__code--empty > div > input"))) | ||
codeInput.send_keys(code) | ||
submitButton = wait.until(ec.element_to_be_clickable((By.CSS_SELECTOR, "button[type=submit]"))) | ||
self.driver.execute_script("arguments[0].click();", submitButton) | ||
self.log.debug("二级验证代码 提交成功") | ||
print("[green]二级验证代码 提交成功") | ||
def insertCode(self): | ||
try: | ||
wait = WebDriverWait(self.driver, 20) | ||
authText = wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, "h5.grid-panel__subtitle"))) | ||
self.log.info(f'请输入二级验证代码 ({authText.text})') | ||
print(f'[yellow]请输入二级验证代码 ({authText.text}') | ||
code = input('二级验证代码: ') | ||
codeInput = wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, "div.codefield__code--empty > div > input"))) | ||
codeInput.send_keys(code) | ||
submitButton = wait.until(ec.element_to_be_clickable((By.CSS_SELECTOR, "button[type=submit]"))) | ||
self.driver.execute_script("arguments[0].click();", submitButton) | ||
self.log.debug("二级验证代码 提交成功") | ||
print("[green]二级验证代码 提交成功") | ||
except Exception as e: | ||
traceback.print_exc() | ||
self.log.error(traceback.format_exc()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.