欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

如何通過Python實現(xiàn)定時打卡小程序

 更新時間:2021年11月25日 15:31:00   作者:leekl_rich  
這篇文章主要為大家詳細介紹了python實現(xiàn)定時打卡小程序,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

目錄結(jié)構(gòu):

只需在自己的python項目下隨便創(chuàng)建一個文件夾(下圖中為:daka),然后將下載的chromedriver.exe、ask_for_leave.py、log.txt(此文件夾為空,保存運行程序時的日志信息,直接在文件夾下創(chuàng)建一個名為log.txt的文件夾即可)。

chromedriver.exe

此文件是google瀏覽器的驅(qū)動文件,可在下載地址上選擇與自己電腦上的google瀏覽器相同版本的驅(qū)動。

如何查看google瀏覽器版本

第一步:打開Chrome瀏覽器

第二步:點擊右上角三個點,選擇“設(shè)置”

第三步:點擊“關(guān)于Chrome”

第四步:得到Chrome版本號

ask_for_leave.py(只需修改標注修改的兩個地方)

from selenium import webdriver
from time import sleep
from selenium.webdriver.common.keys import Keys
import datetime
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.chrome.options import Options
def qinjia(browser,url):
    browser.get(url)
    sleep(1)
    browser.implicitly_wait(3)
    WebDriverWait(browser,5).until(EC.presence_of_all_elements_located((By.ID,"user_main")))
    user_main_div=browser.find_element_by_id("user_main")
    username_input=user_main_div.find_element_by_id("txtId")   #用戶名
    password_input=user_main_div.find_element_by_id("txtMM")    #密碼
    login_btn=user_main_div.find_element_by_id("IbtnEnter")   #登錄按鈕

    # 修改1:此處的賬號和密碼
    username_input.send_keys("==================賬號===================")
    password_input.send_keys("==================密碼===================")
    login_btn.click()

    sleep(1)
    browser.implicitly_wait(3)
    WebDriverWait(browser, 5).until(EC.presence_of_all_elements_located((By.CLASS_NAME, "tabThinM")))
    table_tag=browser.find_element_by_class_name("tabThinM")
    href_body=table_tag.find_elements_by_tag_name("tbody")[2]
    href=href_body.find_elements_by_tag_name("tr")[1].find_element_by_tag_name("a").get_attribute("href")
    browser.get(href)

    table_wjTA=browser.find_element_by_id("wjTA")

    div_gerenjiankang=table_wjTA.find_elements_by_class_name("dvO")[0]  #個人健康
    div_shenqing=table_wjTA.find_elements_by_class_name("dvO")[1]       #申請進入

    # 個人健康
    selects_tag=div_gerenjiankang.find_elements_by_tag_name("select")
    work_station_select=selects_tag[2]
    health_station_select=selects_tag[3]
    live_station_select=selects_tag[4]
    family_station_select=selects_tag[5]

    Select(work_station_select).select_by_value("1")
    Select(health_station_select).select_by_value("1")
    Select(live_station_select).select_by_value("1")
    Select(family_station_select).select_by_value("1")


    #申請進入
    select_shenqin_time_tags=div_shenqing.find_elements_by_tag_name("select")

    input_shenqin_reaseons_tags=div_shenqing.find_elements_by_tag_name("input")
    target_place_input=input_shenqin_reaseons_tags[0]
    reason_input=input_shenqin_reaseons_tags[1]
    # 修改2:成此處的申請目的地和事由
    target_place_input.send_keys("=====================申請目的========================")
    reason_input.send_keys("==========================事由===============================")

    Select(select_shenqin_time_tags[0]).select_by_value("1")
    Select(select_shenqin_time_tags[1]).select_by_value("06")
    Select(select_shenqin_time_tags[2]).select_by_value("3")
    Select(select_shenqin_time_tags[3]).select_by_value("23")

    submit_input=browser.find_element_by_tag_name("input")
    submit_input.click()


def log(message):
    curent_time = datetime.datetime.now()
    print(curent_time)

    f = open("log.txt", "a+", encoding="utf-8")

    f.write(str(curent_time) + ":  "+message+"\n")
    f.close()
def headLessChrome():
    chrome_driver = r"chromedriver.exe"
    chrome_options=Options()
    chrome_options.add_argument("--headless")
    chrome_options.add_argument("--disable-gpu")
    browser=webdriver.Chrome(options=chrome_options, executable_path=chrome_driver)
    return browser
if __name__ == '__main__':
    url="http://login.cuit.edu.cn/Login/xLogin/Login.asp"
    browser=headLessChrome()
    try:
        qinjia(browser,url)
        log("成功")
    except:
        log("失敗")
    browser.quit()

log.txt

直接創(chuàng)建一個空的log.txt文件。

創(chuàng)建完畢之后,run一下ask_for_leave.py文件,即可運行一次。

到此這篇關(guān)于如何通過Python實現(xiàn)定時打卡小程序的文章就介紹到這了,更多相關(guān)Python 定時打卡小程序內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論