Created
August 30, 2020 03:15
-
-
Save MrAru/bda8b50266acdb6db5a10602871420bd to your computer and use it in GitHub Desktop.
Python script to automatically complete Daily Health in XMU
This file contains hidden or 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
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support.expected_conditions import alert_is_present | |
from time import sleep | |
def main(): | |
cookies = { | |
'_dx_captcha_vid': '', # Enter your "_dx_captcha_vid" here | |
'SAAS_U': '', # Enter your "SAAS_U" here | |
'SAAS_S_ID': '' # Enter your "SAAS_S_ID" here | |
} | |
xpath = { | |
'form': '/html/body/div[1]/div/div/div/div/div[1]/div[2]/div/div[3]/div[2]', | |
'selector': '/html/body/div[1]/div/div/div/div/div[2]/div[1]/div/div/div[3]/div/div[22]/div/div/div', | |
'label': '/html/body/div[8]/ul/div/div[3]/li/label', | |
'save': '/html/body/div[1]/div/div/div/div/div[2]/div[1]/div/div/span/span' | |
} | |
with webdriver.Chrome() as driver: | |
driver.get('https://xmuxg.xmu.edu.cn/app/214') | |
driver.add_cookie({'name': '_dx_captcha_vid', 'value': cookies['_dx_captcha_vid']}) | |
driver.add_cookie({'name': 'SAAS_U', 'value': cookies['SAAS_U']}) | |
driver.add_cookie({'name': 'SAAS_S_ID', 'value': cookies['SAAS_S_ID']}) | |
driver.get('https://xmuxg.xmu.edu.cn/app/214') | |
if 'login' in driver.current_url: | |
raise Exception('Cookies outdated') | |
else: | |
WebDriverWait(driver, timeout=10).until(lambda d: d.find_element_by_xpath(xpath['form'])) | |
form = find_elem(driver, xpath['form']) | |
click(driver, form) | |
click(driver, form) | |
WebDriverWait(driver, timeout=10).until(lambda d: d.find_element_by_xpath(xpath['selector'])) | |
selector = find_elem(driver, xpath['selector']) | |
click(driver, selector) | |
label = find_elem(driver, xpath['label']) | |
click(driver, label) | |
save = find_elem(driver, xpath['save']) | |
click(driver, save) | |
WebDriverWait(driver, timeout=10).until(alert_is_present()) | |
driver.switch_to.alert.accept() | |
sleep(5) | |
def find_elem(driver, xpath): | |
return driver.find_element_by_xpath(xpath) | |
def click(driver, elem): | |
webdriver.ActionChains(driver).click(elem).perform() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment