点击核减删除用的代码
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
import time
import datetime
date = str(datetime.date.today())
driver = webdriver.Chrome()
driver.implicitly_wait(30)
driver.get("http://218.59.156.206:8888/bims/")
driver.maximize_window()
driver.find_element(By.ID, "userName").send_keys('')
driver.find_element(By.NAME, "password").send_keys('')
driver.find_element(By.XPATH, "//form/div[3]/input").click()
point = driver.find_element(By.XPATH, "//*[@id='mainSplitter']/div[3]/div/ul/li")
ac = ActionChains(driver)
ac.click(point).perform()
time.sleep(1)
ac.move_to_element_with_offset(point, 108, 46).click().perform()
ac.move_to_element_with_offset(point, 200, 200).perform()
time.sleep(1)
iframe = driver.find_element(By.ID, "mainFrame")
driver.switch_to.frame(iframe)
ac = ActionChains(driver)
point = driver.find_element(By.XPATH, "//*[@id='toolbar']/div[3]/div/button")
ac.click(point).perform()
time.sleep(1)
ac.move_to_element_with_offset(point, 0, 68).click().perform()
point = driver.find_element(By.XPATH, '//button/span[@class="page-size"]')
ac.click(point).perform()
time.sleep(1)
ac.move_to_element_with_offset(point, 0, -35).click().perform()
fo = open("d:/stu.txt", "w", 2048)
fe = open("d:/no.txt", "w", 2048)
driver.find_elements(By.XPATH,"//tr[@date-index='0']")
points = driver.find_elements(By.XPATH, "//*[@id='rightTable']/tbody/tr")
for td in points:
list_ = td.text.split(' ')
index = 3
if len(list_[4])==1:
index = 4
elif len(list_[5])==1:
index = 5
fo.write(list_[0] + "\t" + list_[1] + "\t" + list_[index] + "\t" + list_[index+1] + "\t" + list_[index+2] + "\n" )
if list_[index+1]!= date:
fe.write(list_[1][6:10] + list_[1][15:] + list_[0] + "\n")
driver.find_element(By.LINK_TEXT, "2").click()
driver.find_elements(By.XPATH,"//tr[@date-index='0']")
points = driver.find_elements(By.XPATH, "//*[@id='rightTable']/tbody/tr")
for td in points:
list_ = td.text.split(' ')
index = 3
if len(list_[4])==1:
index = 4
elif len(list_[5])==1:
index = 5
fo.write(list_[0] + "\t" + list_[1] + "\t" + list_[index] + "\t" + list_[index+1] + "\t" + list_[index+2] + "\n" )
if list_[index+1]!= date:
fe.write(list_[1][6:10] + list_[1][15:] + list_[0] + "\n")
driver.find_element(By.LINK_TEXT, "3").click()
driver.find_elements(By.XPATH,"//tr[@date-index='0']")
points = driver.find_elements(By.XPATH, "//*[@id='rightTable']/tbody/tr")
for td in points:
list_ = td.text.split(' ')
index = 3
if len(list_[4])==1:
index = 4
elif len(list_[5])==1:
index = 5
fo.write(list_[0] + "\t" + list_[1] + "\t" + list_[index] + "\t" + list_[index+1] + "\t" + list_[index+2] + "\n" )
if list_[index+1]!= date:
fe.write(list_[1][6:10] + list_[1][15:] + list_[0] + "\n")
fo.close()
fe.close()
print("end!")
不用点核减删除,直接生成两个文件
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import datetime
list_no = []
dict_class = {}
with open("name_class.txt", 'r') as frd:
for line in frd:
dw = line.strip().split('\t')
dict_class[dw[0]] = dw[1]
date = str(datetime.date.today())
str_date = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M')
driver = webdriver.Chrome()
driver.implicitly_wait(20)
driver.get("http://218.59.156.206:8888/bims/")
driver.maximize_window()
driver.find_element(By.ID, "userName").send_keys('')
driver.find_element(By.NAME, "password").send_keys('')
driver.find_element(By.XPATH, "//form/div[3]/input").click()
iframe = driver.find_element(By.ID, "mainFrame")
driver.switch_to.frame(iframe)
driver.find_element(By.XPATH, '//button/span[@class="page-size"]').click()
driver.find_element(By.XPATH, '//span[@class="page-list"]/span/ul/li[5]').click()
fo = open("all" + str_date + ".txt", "w", 2048)
driver.find_elements(By.XPATH,"//tr[@date-index='0']")
points = driver.find_elements(By.XPATH, "//*[@id='rightTable']/tbody/tr")
for td in points:
list_ = td.text.split(' ')
index = len(list_) - 4
fo.write(list_[0] + "\t" + list_[1] + "\t" + list_[index-1] + "\t" + list_[index] + "\t" + list_[index+2] + "\n" )
if list_[index]!= date:
list_no.append(list_[1][6:10] + list_[1][15:] + list_[0])
driver.find_element(By.LINK_TEXT, "2").click()
driver.find_elements(By.XPATH,"//tr[@date-index='0']")
points = driver.find_elements(By.XPATH, "//*[@id='rightTable']/tbody/tr")
for td in points:
list_ = td.text.split(' ')
index = len(list_) - 4
fo.write(list_[0] + "\t" + list_[1] + "\t" + list_[index-1] + "\t" + list_[index] + "\t" + list_[index+2] + "\n" )
if list_[index]!= date:
list_no.append(list_[1][6:10] + list_[1][15:] + list_[0])
driver.find_element(By.LINK_TEXT, "3").click()
driver.find_elements(By.XPATH,"//tr[@date-index='0']")
points = driver.find_elements(By.XPATH, "//*[@id='rightTable']/tbody/tr")
for td in points:
list_ = td.text.split(' ')
index = len(list_) - 4
fo.write(list_[0] + "\t" + list_[1] + "\t" + list_[index-1] + "\t" + list_[index] + "\t" + list_[index+2] + "\n" )
if list_[index]!= date:
list_no.append(list_[1][6:10] + list_[1][15:] + list_[0])
fo.close()
list_no.sort()
with open("no" + str_date + ".txt", 'w') as fw:
for ren in list_no:
if int(ren[:4]) < 2002 :
fw.write(ren[7:] + '\n')
else:
fw.write(ren[7:] + '\t' + dict_class.get(ren, "未知") + '\n')
print("end!")
用显示等待的代码
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import datetime
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
list_no = []
dict_class = {}
with open("name_class.txt", 'r') as frd:
for line in frd:
dw = line.strip().split('\t')
dict_class[dw[0]] = dw[1]
date = str(datetime.date.today())
str_date = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M')
driver = webdriver.Chrome()
driver.get("http://218.59.156.206:8888/bims/")
driver.maximize_window()
driver.find_element(By.ID, "userName").send_keys('')
driver.find_element(By.NAME, "password").send_keys('')
driver.find_element(By.XPATH, "//form/div[3]/input").click()
iframe = driver.find_element(By.ID, "mainFrame")
driver.switch_to.frame(iframe)
driver.find_element(By.XPATH, '//button/span[@class="page-size"]').click()
driver.find_element(By.XPATH, '//span[@class="page-list"]/span/ul/li[5]').click()
with open("all" + str_date + ".txt", 'w',2048) as fo:
locator = (By.XPATH,"//*[@id='rightTable']/tbody/tr")
WebDriverWait(driver,20).until(EC.presence_of_element_located(locator))
time.sleep(2)
points = driver.find_elements(By.XPATH, "//*[@id='rightTable']/tbody/tr")
for td in points:
list_ = td.text.split(' ')
index = len(list_) - 4
fo.write(list_[0] + "\t" + list_[1] + "\t" + list_[index-1] + "\t" + list_[index] + "\t" + list_[index+2] + "\n" )
if list_[index]!= date:
list_no.append(list_[1][6:10] + list_[1][15:] + list_[0])
driver.find_element(By.LINK_TEXT, "2").click()
WebDriverWait(driver,20).until(lambda _:driver.find_elements(By.XPATH,"//*[@id='rightTable']/tbody/tr"))
time.sleep(2)
points = driver.find_elements(By.XPATH, "//*[@id='rightTable']/tbody/tr")
for td in points:
list_ = td.text.split(' ')
index = len(list_) - 4
fo.write(list_[0] + "\t" + list_[1] + "\t" + list_[index-1] + "\t" + list_[index] + "\t" + list_[index+2] + "\n" )
if list_[index]!= date:
list_no.append(list_[1][6:10] + list_[1][15:] + list_[0])
driver.find_element(By.LINK_TEXT, "3").click()
WebDriverWait(driver,20).until(lambda _:driver.find_elements(By.XPATH,"//*[@id='rightTable']/tbody/tr"))
time.sleep(2)
points = driver.find_elements(By.XPATH, "//*[@id='rightTable']/tbody/tr")
for td in points:
list_ = td.text.split(' ')
index = len(list_) - 4
fo.write(list_[0] + "\t" + list_[1] + "\t" + list_[index-1] + "\t" + list_[index] + "\t" + list_[index+2] + "\n" )
if list_[index]!= date:
list_no.append(list_[1][6:10] + list_[1][15:] + list_[0])
list_no.sort()
with open("no" + str_date + ".txt", 'w',2048) as fw:
for ren in list_no:
if int(ren[:4]) < 2002 :
fw.write(ren[7:] + '\n')
else:
fw.write(ren[7:] + '\t' + dict_class.get(ren, "未知") + '\n')
driver.close()
print("end!")
复制网站每个人信息运行程序处理好的信息放入剪切板
'''
程序功能:选定并复制好网站人员的信息后,运行本程序,剪切板里面是人员名单和班级
程序进入条件:
name_class.txt:存放人员id及班级信息,格式为 2009216魏子旭 8.1 (身份证年加身份证后3位)
剪切板里面的复制格式:每行格式为 刘迎奥 3708282007*****239 159****4892 学生 2022-10-05 06:32:24 3 8.5班
程序输出时剪板里面的格式:名字 班级
'''
import pyperclip
list_id = []
str_temp = pyperclip.paste()
list_lines = str_temp.split("\n")
for line in list_lines:
list_ = line.strip().split("\t",2)
list_id.append(list_[1][6:10] + list_[1][15:] + list_[0])
list_id.sort()
dict_ = {}
with open("name_class.txt", 'r') as frd:
for line in frd:
line = line.strip()
listd = line.split('\t')
dict_[listd[0]] = listd[1]
str_temp = ""
for ren in list_id:
if int(ren[:4]) < 2002 :
str_temp += ren[7:] + '\n'
else:
str_temp += ren[7:] + '\t' + dict_.get(ren, "未知") + '\n'
pyperclip.copy(str_temp)
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· 【.NET】调用本地 Deepseek 模型
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)