發表文章

目前顯示的是有「python」標籤的文章

python - auto Check in to work

a python program for auto check in to work on web site selenium need other browser driver # -*- coding: utf-8 -*- import time import random from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Chrome() # Optional argument, if not specified will search path. driver.get( 'company url' ) # random time login(10s-30min time.sleep(random.randint( 10 , 1800 )) # Let the user actually see something! try : # find xpath of account & password driver.find_element_by_xpath( "//*[@id='userid_input']" ).send_keys( "account" ) driver.find_element_by_xpath( "//*[@id='password']" ).send_keys( "password" ) # click login button driver.find_element_by_xpath( "/html/body/form/table[2]/tbody/tr/td[2]/table/tbody/tr[3]/td[2]/div/a/img" ).click() time.sleep( 5 ) # click login page driver.find_element_by_link_text( " 今日出勤班別 " ).click() time.sl...

python - Compare & Change File Name

圖片
In response to work needs write a python script for compare & change file name from excel file the script will compare field "servicetag" data in sheet "host" & file name Reference file (demo.xlsx)formate code import os , re , pandas # rename file count count = 0 # get script root path desdir=os.getcwd() # get xlsx file path datafile = input ( "xlsx file path \n " ) #load xlsx file data df = pandas.read_excel(datafile , sheet_name = 'host' ) df_df=pandas.DataFrame(df) for i in range ( len (df_df)): for file in os.listdir(desdir): if bool (re.search(df_df[ 'servicetag' ][i] , file)): #file name check if bool (re.search(df_df[ 'host' ][i] , file)): break ; else : count =count+ 1 os.rename(os.path.join(desdir , file) , os.path.join(desdir , df_df[ 'host' ][i]+ '-' +fi...