72 lines
1.9 KiB
Python
72 lines
1.9 KiB
Python
#! /usr/bin/env python
|
|
|
|
import sys
|
|
|
|
import html5lib
|
|
|
|
from selenium import webdriver
|
|
from selenium.webdriver.support.ui import WebDriverWait
|
|
from selenium.webdriver.chrome.options import Options
|
|
from selenium.webdriver.common.by import By
|
|
|
|
# credentials
|
|
username = "marko"
|
|
password = "kodokan"
|
|
|
|
# initialize the Chrome driver
|
|
chromeOptions = Options()
|
|
chromeOptions.headless = True
|
|
driver = webdriver.Chrome(options=chromeOptions)
|
|
|
|
html5Parser = html5lib.HTMLParser(strict=True)
|
|
|
|
# head to login page
|
|
driver.get("http://cwsvjudo.bplaced.net/participo/")
|
|
# find username/email field and send the username itself to the input field
|
|
driver.find_element("id", "username").send_keys(username)
|
|
# find password input field and insert password as well
|
|
driver.find_element("id", "password").send_keys(password)
|
|
# click login button
|
|
driver.find_element("name", "submit").click()
|
|
|
|
|
|
# wait the ready state to be complete
|
|
WebDriverWait(driver=driver, timeout=10).until(
|
|
lambda x: x.execute_script("return document.readyState === 'complete'")
|
|
)
|
|
|
|
# Open the sidemenu if necessary
|
|
for m in driver.find_elements(By.CLASS_NAME, "material-icons"):
|
|
if m.text == "menu":
|
|
m.click()
|
|
|
|
try:
|
|
html5Parser.parse("<!DOCTYPE html > "+driver.page_source)
|
|
print("mainpage ok")
|
|
except Exception as e:
|
|
print(repr(e), file=sys.stderr)
|
|
print(driver.page_source)
|
|
|
|
loginText = "Eingeloggt als " + username
|
|
divList = driver.find_elements(By.TAG_NAME, 'li')
|
|
|
|
if not any(loginText in d.text for d in divList):
|
|
print("login failed", file=sys.stderr)
|
|
driver.close()
|
|
driver.quit()
|
|
exit(-1)
|
|
|
|
for pageName in ["events", "attendance", "kyu", "user"]: # missing: "infoZettel"
|
|
driver.get("http://cwsvjudo.bplaced.net/participo/"+pageName)
|
|
|
|
try:
|
|
html5Parser.parse("<!DOCTYPE html>"+driver.page_source)
|
|
print(f"{pageName} ok")
|
|
except Exception as e:
|
|
print(repr(e), file=sys.stderr)
|
|
print(driver.page_source)
|
|
|
|
|
|
driver.close()
|
|
driver.quit()
|