import re
import time
import datetime
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait as Wait
driver = webdriver.Chrome("chromedriver.exe") # chromedriver所在路径
def DengLuJianCha():
driver.get(
r"https://onehall.bnu.edu.cn/tp_fp/view?m=fp#from=hall&serveID=e87d2875-6fcf-4e6a-81bc-8ff99915aed3&act=fp/serveapply")
def isLoginShow():
now_url = driver.current_url
result = re.findall("cas", now_url)
if result != []:
driver.find_element(By.ID, "un").send_keys("202*********") # ------在这里输入你的学号
driver.find_element(By.ID, "pd").send_keys("*********") #----------在这里输入你的数字京师信息门户的密码
driver.find_element(By.ID, "index_login_btn").click()
isLoginShow()
DengLuJianCha()
# 判断新页面是否加载完成
print("等下缓缓")
Wait(driver, 60).until(EC.presence_of_element_located((By.ID, "text_SearchService")))
print("阔以了干活")
QianDaoTianShu = 200 #----------------------输入你打算签到的天数(有个目前还未知的小bug,有时候连续申请超过30天就得重新运行这个文件)
QiShiRiQi = "2022-08-24" #-------------------输入签到起始日期, 应该是你打算的起始日期的前一天 哈哈 我懒得改了
def get_diff_days_2_now(date_str):
now_time = time.localtime(time.time())
compare_time = time.strptime(date_str, "%Y-%m-%d")
# 比较日期
date1 = datetime.datetime(compare_time[0], compare_time[1], compare_time[2])
date2 = datetime.datetime(now_time[0], now_time[1], now_time[2])
diff_days = (date2 - date1).days
return diff_days
deltaDay = -get_diff_days_2_now(QiShiRiQi)
for i in range(1, QianDaoTianShu):
time.sleep(5)
driver.get(
r"https://onehall.bnu.edu.cn/tp_fp/view?m=fp#from=hall&serveID=e87d2875-6fcf-4e6a-81bc-8ff99915aed3&act=fp"
r"/serveapply")
# 判断临时出校申请的新页面是否加载完成
Wait(driver, 60).until(EC.presence_of_element_located((By.ID, "mag_take_cancel")))
print("准备就绪")
time.sleep(5) # 等待时间
print("结束等待")
now_url = driver.current_url
def main_work():
driver.find_element(By.XPATH, "//button[text()='我已阅读并确认']").click()
#driver.find_element(By.CSS_SELECTOR,'button[#mag_take_cancel]').click()
time.sleep(2)
print("我已阅读")
driver.switch_to.frame("formIframe")
driver.find_element(By.ID, "LXDH").send_keys("13121896752")
driver.find_element(By.ID, "SSL").send_keys("90")
driver.find_element(By.ID, "SSH").send_keys("911")
driver.find_element(By.ID, "CXYY").send_keys("做实验")
driver.find_element(By.ID, "JTDZ").send_keys("北太平庄")
driver.find_element(By.ID, "ZYJCRQ").send_keys("学生")
# 出校日期 改为直接输入方式 readonly 为 false
js = """var rs = document.querySelectorAll("input[readonly='readonly']");for(var i = 0; i < rs.length; i++){rs[i].readOnly = false;}"""
driver.execute_script(js)
driver.find_element(By.XPATH, '//*[@id="is_back_vant"]/div/div[1]/div/i').click();
driver.find_element(By.XPATH, '//*[@id="is_out_vant"]/div/div[2]/div/i').click();
# 出校原因
driver.find_element(By.XPATH, '// *[ @ id = "body_0"] / div[1] / div[6] / div[2] / div / button').click();
driver.find_element(By.XPATH, '//*[@id="body_0"]/div[1]/div[6]/div[2]/div/div/ul/li[2]/a/span').click();
# 出校省
driver.find_element(By.XPATH, '//*[@id="body_0"]/div[1]/div[8]/div[2]/div/button/span[1]').click();
driver.find_element(By.XPATH, '//*[@id="body_0"]/div[1]/div[8]/div[2]/div/div/ul/li[2]/a/span').click();
# 出校市
driver.find_element(By.XPATH, '//*[@id="body_0"]/div[1]/div[8]/div[4]/div/button/span[1]').click();
driver.find_element(By.XPATH, '//*[@id="body_0"]/div[1]/div[8]/div[4]/div/div/ul/li[2]/a/span').click();
# 出校县
driver.find_element(By.XPATH, '//*[@id="body_0"]/div[1]/div[9]/div[2]/div/button/span[1]').click();
driver.find_element(By.XPATH, '//*[@id="body_0"]/div[1]/div[9]/div[2]/div/div/ul/li[7]/a/span').click();
def oi_time(): # 出入校时间
now = datetime.datetime.now()
delta = datetime.timedelta(days=i+deltaDay)
n_days = now + delta
RiQi = n_days.strftime('%Y-%m-%d')
print(RiQi)
# 出校&返校时间
driver.find_element(By.ID, "sdate").send_keys(RiQi)
driver.find_element(By.ID, "edate").send_keys(RiQi)
oi_time()
driver.find_element(By.XPATH, '// *[ @ id = "btn_uploader_0"]').send_keys(u'E:\健身\experiment.jpg')
time.sleep(3)
driver.switch_to.default_content()
driver.find_element(By.ID, "commit").click()
main_work()
print("已完成: ", i)
# DengLuJianCha()
driver.close()
我们实验室就在校外,天天申请出校,真讨厌。开始还有个自动填写功能的,现在也没了,并且不出京,你还整 北京市-XX区-XX街道。。。这就太讨厌了哇。生气之下,自己撸代码让他自动填吧。也当解救一下北师的小伙伴吧 哈哈
需要导入selenium库,自己下载chromedriver软件,自行百度,一搜一大片。
|