from os.path import isfile, isdir, join
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
以資料夾名稱來判斷時間,會這樣設定是因為雲端空間在手機端操作比較方便,省去打開文件
mypath = "D:\Google雲端硬碟\sync\上班打卡用"
c_time1 = re.findall('\d{4}',c_time0)
c_time2 = re.split("",c_time1[0])
c_time3 = c_time2[1]+c_time2[2]+":"+c_time2[3]+c_time2[4]
for tt in range(t3,0,-1):
os.rmdir(mypath+"\\"+c_time0)
n_time = datetime.datetime.now()
for tt in range(t3,0,-1):
d_time = datetime.datetime.strptime(str(datetime.datetime.now().date())+c_time3, '%Y-%m-%d%H:%M')
n_time = datetime.datetime.now()
deltatime = (d_time - n_time).seconds -120
print("打卡倒數時間=",str(datetime.timedelta(seconds=deltatime)),"≒",deltatime,"秒")
for x in range(deltatime,0,-1):
print("打卡時間小於目前時間,不符合邏輯,程式10秒後自動關閉")
利用firefox的selenuim記錄,最方便,但是程式碼需要修正才行
by_id(xxx)這部分錄製的程式碼不符合python3,需要手動修正
driver = webdriver.Firefox()
rantime = random.randint(6,60)
driver.find_element_by_id("txtUser10").send_keys("__帳號__")
driver.find_element_by_id("txtPwd10").send_keys("__密碼__")
driver.find_element_by_id("btnCheckIn10").click()
os.rmdir(mypath+"\\"+c_time0)
smtp_server = "smtp.gmail.com"
context = ssl.create_default_context()
with smtplib.SMTP_SSL(smtp_server, port, context=context) as server:
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, message)