Skip to content

Instantly share code, notes, and snippets.

@ink19
Last active December 8, 2021 03:43
Show Gist options
  • Save ink19/00ebf74f5301f7f033e7518c639ec74c to your computer and use it in GitHub Desktop.
Save ink19/00ebf74f5301f7f033e7518c639ec74c to your computer and use it in GitHub Desktop.
checkin.py
#!/usr/bin/env python3
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
import SendMessage
# 填写信息
config = [{
'username': '学号',
'password': '密码'
}]
def CheckIn(username, password):
chrome_options = webdriver.ChromeOptions()
# 使用headless无界面浏览器模式
chrome_options.add_argument('--headless') # 增加无界面选项
chrome_options.add_argument('--disable-gpu') # 如果不加这个选项,有时定位会出现问题
# chrome_options.add_argument('--proxy-server=socks5://127.0.0.1:1080')
# 启动浏览器,获取网页源代码
browser = webdriver.Chrome(chrome_options=chrome_options)
browser.implicitly_wait(30)
try:
mainUrl = "https://newids.seu.edu.cn/authserver/login"
browser.get(mainUrl)
# 登陆
username_input = browser.find_element_by_id("username")
password_input = browser.find_element_by_id("password")
submit_button = browser.find_element_by_tag_name("button")
username_input.send_keys(username)
password_input.send_keys(password)
submit_button.click()
browser.get_screenshot_as_file("login.png")
## 打卡
browser.get("http://ehall.seu.edu.cn/qljfwapp2/sys/lwReportEpidemicSeu/index.do#/dailyReport")
WebDriverWait(browser,10).until(EC.visibility_of_element_located((By.ID,'contenttableemapdatatable')))
browser.get_screenshot_as_file("report.png")
## 打卡button
browser.find_element_by_css_selector("[class='bh-btn bh-btn-primary']").click()
WebDriverWait(browser,10).until(EC.visibility_of_element_located((By.ID,'save')))
browser.find_element_by_name("DZ_JSDTCJTW").send_keys("36.5")
browser.find_element_by_id("save").click()
browser.find_element_by_xpath("//a[text()='确认']").click()
browser.get_screenshot_as_file("report_after.png")
except:
SendMessage.SendMessage(username + "打卡失败!!!")
finally:
browser.quit()
for item in config:
CheckIn(item['username'], item['password'])
#!/usr/bin/env python3
import sys
import json
import requests
from requests.api import head
def SendMessage(text: str) -> None:
send_url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=url_key"
send_data = json.dumps({
"msgtype": "text",
"text": {
"content": text
}
})
header={
"Content-Type": "application/json"
}
requests.post(send_url, data=send_data, headers=header)
if __name__ == "__main__":
SendMessage(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment