阿里云+python完成南京大学健康打卡上报
首先去阿里云官网买一个最便宜的服务器(轻量级服务器即可),然后镜像选择为ubuntu 18.04
之后需要在该服务器上安装python 3.7,这个网上的教程很多,自己搜索 阿里云ubuntu 18.4 python 3.7就好了,然后需要在服务器安装Chrome浏览器和ChromeDriver驱动
环境配置好之后 上代码,需要自己输入账号,密码和打卡地点(地点在注释里面),程序用了selenium类,因为比较方便。
from unittest import mock
def get_chrome_driver():
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("headless")
options.add_argument('--no-sandbox')
options.add_argument('--disable-gpu')
options.add_argument('--disable-dev-shm-usage')
return webdriver.Chrome(options=options)
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 bs4 import BeautifulSoup
import json
username = '' # 用户名
password = '' # 密码
curr_location = '' # 打卡地点
def fillOneForm(wid):
info = '&IS_TWZC=1&IS_HAS_JKQK=1&JRSKMYS=1&JZRJRSKMYS=1'
link = 'http://ehallapp.nju.edu.cn/xgfw/sys/yqfxmrjkdkappnju/apply/saveApplyInfos.do?WID={wid}&CURR_LOCATION={curr_location}'
link = link.format(wid=wid, curr_location=curr_location) + info
driver.get(link)
html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')
ss = soup.select('pre')[0]
res = json.loads(ss.text)
if res['code'] == '0':
if res['msg'] == '成功':
return 'Success!'
return 'Failed.'
def fillTheForms(res):
form = res[0]
if form['TBZT'] == '0':
print('Date: ' + form['TBRQ'] + ' ' + fillOneForm(form['WID']))
if __name__ == "__main__":
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-gpu')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('blink-settings=imagesEnabled=false')
options.add_experimental_option('excludeSwitches', ['enable-automation'])
options.add_argument('log-level=3')
driver = webdriver.Chrome(options=options)
driver.get('https://authserver.nju.edu.cn/authserver/login')
while True:
try:
element = WebDriverWait(browser, 0.5).until(EC.presence_of_element_located((By.ID,"username")))
finally:
break
driver.find_element_by_id("username").send_keys(username)
driver.find_element_by_id("password").send_keys(password)
driver.find_element_by_class_name("auth_login_btn").click()
driver.get('http://ehallapp.nju.edu.cn/xgfw/sys/yqfxmrjkdkappnju/apply/getApplyInfoList.do')
html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')
ss = soup.select('pre')[0]
res = json.loads(ss.text)
if res['code'] == '0':
if res['msg'] == '成功':
fillTheForms(res['data'])
print('Completed')
driver.quit()
这个.py文件如何上传到服务器呢?
不要直接在服务器复制粘贴,程序会报错!!!
使用Xshell和xftp这两个软件上传,网上都有教程
上传之后如何定时打卡呢?
使用crontab -e这个代码 教程如下(在最后面)
配置完毕后,即可开始打卡