某学校自动一键申请出校(5月9日至7月10日)(selenium+chrome webdrive)

对于要实习的同学/有大量出去兼职/上海旅游/吃饭到处浪的同学每天都要申请出校太麻烦了,有时候忘记了还要在门口等5分钟使用python模块的selenium 就尝试使用此方法自动申请出校(此方法仅供校内同学分享哈哈哈,不作商用~)
如果不想下载python和谷歌浏览器相信我的话可以把你的oa账号密码发给我我帮你完成哈哈哈~
学python就是搞这玩意好用
步骤:
1.下载安装python

2.下载安装chrome
地址:https://www.google.cn/chrome/
3.安装selenium
打开cmd 执行pip install selenium

4.下载安装你的chrome版本的webdriver
地址:https://chromedriver.storage.googleapis.com/index.html
注意浏览器驱动 必须要和浏览器版本匹配 浏览器版本可以在谷歌浏览器右上角…点击下面的帮助–》关于 查看版本号
打开目录,里面有3个zip包,分别对应Linux、Mac、Windows平台。

如果我们是Windows平台的电脑,就下载 chromedriver_win32.zip

5.运行代码

import time
from selenium import webdriver
# 导入Select类
from selenium.webdriver.support.ui import Select
# 创建Select对象
chrome_options=webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
wd = webdriver.Chrome(r'C:\Users\humeiersi777\Downloads\chromedriver_win32\chromedriver.exe',options=chrome_options)
wd.implicitly_wait(10)
wd.get('https://id.sspu.edu.cn/cas/login')
#登录账号密码
username=wd.find_element_by_id('username')
password=wd.find_element_by_id('password')
btn=wd.find_element_by_css_selector('.submit_button')
username.send_keys('你的OA账号')
password.send_keys('你的密码')
btn.click()
time.sleep(1)
a=wd.find_element_by_tag_name('a')
a.click()
#跳转到登录后页面
for handle in wd.window_handles:
    # 先切换到该窗口
    wd.switch_to.window(handle)
    # 得到该窗口的标题栏字符串,判断是不是我们要操作的那个窗口
    if 'Bing' in wd.title:
        # 如果是,那么这时候WebDriver对象就是对应的该该窗口,正好,跳出循环,
        break
# 在oa里面进入出校申请页面
fre=wd.find_element_by_css_selector('.freqUse')
fre.click()
time.sleep(1)
new=wd.find_element_by_css_selector('span[title="新建流程"]')
new.click()
time.sleep(1)
wd.switch_to.frame('mainFrame')
btn=wd.find_element_by_css_selector('#tab_1 a')
btn.click()
wd.switch_to.frame('tabcontentframe')
mainWindow = wd.current_window_handle

def go_to_school(num1,num2,a,timer):
    chuxiaola = wd.find_element_by_xpath(
        '/html/body/table[2]/tbody/tr[2]/td[2]/table/tbody/tr/td/table/tbody/tr[1]/td[1]/div[2]/div[2]/div[9]/div[1]/a')
    chuxiaola.click()
    for handle in wd.window_handles:
        # 先切换到该窗口
        wd.switch_to.window(handle)
        # 得到该窗口的标题栏字符串,判断是不是我们要操作的那个窗口
        if 'Bing' in wd.title:
            # 如果是,那么这时候WebDriver对象就是对应的该该窗口,正好,跳出循环,
            break
    # 进入到申请页面
    wd.switch_to.frame('bodyiframe')
    time.sleep(1)
    thing = wd.find_element_by_id('field11241')
    thing.send_keys('.')
    select = Select(wd.find_element_by_id("field11404"))
    select.select_by_visible_text("本专科生")
    select2 = Select(wd.find_element_by_id("field12523"))
    select2.select_by_visible_text("否")
    select3 = Select(wd.find_element_by_id("field11663"))
    select3.select_by_visible_text("外出实习")
    select4 = Select(wd.find_element_by_id("field11251"))
    select4.select_by_visible_text(timer)  # 出校时间
    btn2 = wd.find_element_by_id('field11304_browserbtn')
    btn2.click()
    select5 = Select(wd.find_element_by_id("field11255"))
    select5.select_by_visible_text(timer)  # 返校时间
    time.sleep(1)

    wd.switch_to.default_content()
    wd.switch_to.frame(wd.find_element_by_css_selector('div div iframe:nth-child(2)'))
    wd.switch_to.frame('main')
    way = wd.find_element_by_xpath('//*[@id="e8_src_table"]/tbody/tr[4]')
    way.click()
    img = wd.find_element_by_id('singleArrowTo')
    img.click()
    for_sure = wd.find_element_by_xpath('//*[@id="btnok"]')
    for_sure.click()
    wd.switch_to.default_content()
    wd.switch_to.frame('bodyiframe')
    select2 = Select(wd.find_element_by_id("field12523"))
    select2.select_by_visible_text("是")
    select2 = Select(wd.find_element_by_id("field12523"))
    select2.select_by_visible_text("否")
    date = wd.find_element_by_id('field11250browser')
    date.click()
    time.sleep(1)
    wd.switch_to.frame(wd.find_element_by_xpath('//*[@id="_my97DP"]/iframe'))
    # 出校时间Case1: 今天
    # today = wd.find_element_by_id('dpTodayInput')
    # today.click()
    #注意!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    if a==0:
        day=wd.find_element_by_css_selector(f'.WdayTable tr:nth-child({num1}) td:nth-child({num2})')
        day.click()
    if a==1:
        change_data=wd.find_element_by_xpath('//*[@id="dpTitle"]/div[6]/a')
        change_data.click()
        day=wd.find_element_by_css_selector(f'.WdayTable tr:nth-child({num1}) td:nth-child({num2})')
        day.click()
    # Case2:一键自动申请4月剩下每天
    # 返校日期
    wd.switch_to.default_content()
    wd.switch_to.frame('bodyiframe')
    date = wd.find_element_by_id('field13063browser')
    date.click()
    time.sleep(1)
    wd.switch_to.frame(wd.find_element_by_xpath('//*[@id="_my97DP"]/iframe'))
    # today = wd.find_element_by_id('dpTodayInput')
    # today.click()
    #注意!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    if a==0:
        reday=wd.find_element_by_css_selector(f'.WdayTable tr:nth-child({num1}) td:nth-child({num2})')
        reday.click()
    if a == 1:
        change_data = wd.find_element_by_xpath('//*[@id="dpTitle"]/div[6]/a')
        change_data.click()
        reday=wd.find_element_by_css_selector(f'.WdayTable tr:nth-child({num1}) td:nth-child({num2})')
        reday.click()
    time.sleep(1)
    wd.switch_to.default_content()
    wd.switch_to.frame('bodyiframe')
    select7 = Select(wd.find_element_by_xpath('//*[@id="field11259"]'))
    select7.select_by_visible_text("良好")
    fin1 = wd.find_element_by_xpath(
        '//*[@id="flowbody"]/form/div[1]/table/tbody/tr/td/table/tbody/tr[21]/td/div/span[1]/span/span')
    fin1.click()
    fin2 = wd.find_element_by_xpath(
        '//*[@id="flowbody"]/form/div[1]/table/tbody/tr/td/table/tbody/tr[22]/td/div/span[1]/span/span')
    fin2.click()
    wd.switch_to.default_content()
    sub = wd.find_element_by_css_selector('.e8_btn_top_first')
    sub.click()
    print(f'第{num1}行第{num2}列完成')
    wd.switch_to.window(mainWindow)
    wd.switch_to.frame('mainFrame')
    wd.switch_to.frame('tabcontentframe')

def good_morning():
    for i in range(4, 8):
        for i2 in range(1, 8):
            if i==1 or i==2 or i==3:
                continue
            else:
                go_to_school(i,i2,0,"00:00-12:00")
    for i in range(3, 8):
        for i2 in range(1, 8):
            if i == 1 or i == 2:
                continue
            else:
                go_to_school(i,i2,1,"00:00-12:00")
    # 如果只需要白天出校的同学
def good_night():
    for i in range(4, 8):
        for i2 in range(1, 8):
            if i == 1 or i == 2 or i == 3:
                continue
            else:
                go_to_school(i, i2, 0, "12:00-00:00")
    for i in range(3, 8):
        for i2 in range(1, 8):
            if i == 1 or i == 2:
                continue
            else:
                go_to_school(i, i2, 1, "12:00-00:00")
def main():
    # 如果只需要晚上出校的同学 请删除以下这行代码
    good_morning()
    #如何只需要白天出校的同学 请删除以下代码
    good_night()



if __name__ == '__main__':
    main()







  
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值