加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
LDAP is enabled.py 3.87 KB
一键复制 编辑 原始数据 按行查看 历史
罗兴 提交于 2024-08-09 10:35 . rename ldap2.py to LDAP is enabled.py.
import time
import xlrd
from DrissionPage import ChromiumPage
stat_time = time.time()
# 打开表格
open_list = xlrd.open_workbook('table.xls')
# 获取sheet
sheet = open_list.sheet_by_index(0)
# 获取该sheet的有效行
rows = sheet.nrows
# 创建页面对象,并启动或接管浏览器
page = ChromiumPage()
# 跳转到登录页面
page.get("www.baidu.com")
# 登录
# 定位输入框
def login_user():
passwd = page.ele('tag:input@@type=password@@class=ui-corner-all@@name=passwd@@id=passwd@@maxlength=1000@@size=30@@tabindex=2').input('22424')
# 确定
page.ele('tag:button@@id=btn_checklogin@@name=checklogin@@tabindex=4@@type=submit@@class=smallPadding ui-button ui-corner-all ui-widget@@text()=登录').click()
# 点击新用户
page.ele('tag:button@@id=btn_new@@name=new@@tabindex=4@@type=submit@@class=fullwidth-mobile-only margin5 ui-button ui-corner-all ui-widget@@text()= 新用户').click()
# 循环获取行数据
for row in range(1, rows):
data = sheet.row_values(row)
name = data[0]
spell_name = data[2]
phone_num = int(data[4])
email_num = data[2] + "@baidu.cn"
password = data[5]
# print(name + "开始注册....")
login_user()
username = page.ele('tag:input@@type=text@@class=validate[required] ui-corner-all lam-autotrim@@name=sn@@id=sn@@maxlength=1000@@tabindex=5001').input(name)
time.sleep(0.5)
# username.clear()
#电话号码
phone = page.ele('tag:input@@type=text@@class=ui-corner-all lam-autotrim@@name=mobile_0@@id=mobile_0@@maxlength=1000@@size=30@@tabindex=5026').input(phone_num)
time.sleep(0.5)
# 邮箱
emails = page.ele('tag:input@@type=text@@class=ui-corner-all lam-autotrim@@name=mail_0@@id=mail_0@@maxlength=1000@@size=30@@tabindex=5030').input(email_num)
time.sleep(0.5)
# Unix
element = page.ele('xpath://*[@id="lamVerticalTabs"]/table/tbody/tr/td[1]/ul/li[2]/button')
element.click()
#输入用户名
page.ele(".validate[required] ui-corner-all lam-autotrim").click
page.ele(".validate[required] ui-corner-all lam-autotrim").clear()
page.ele(".validate[required] ui-corner-all lam-autotrim").input(spell_name)
# 输入全名
page.ele(".ui-corner-all lam-autotrim").click
page.ele(".ui-corner-all lam-autotrim").clear()
page.ele(".ui-corner-all lam-autotrim").input(spell_name)
#设置主要组为employee
element = page.ele('xpath://*[@id="lamVerticalTabs"]/table/tbody/tr/td[1]/ul/li[2]/button')
element.click()
# 等待页面加载
time.sleep(0.5)
# 点击选项值为10000
#option_element = page.ele('xpath://option[@value="10001" and text()="Grafana"]')
option_element_employee = page.ele('xpath://option[@value="10000" and text()="employee"]')
option_element_employee.click()
time.sleep(0.5)
#设置密码
elem = page.ele('#btn_accountContainerPassword')
elem.click() # 点击元素
time.sleep(0.5)
#输入密码
passwd1 = page.ele('#newPassword1').input(password)
time.sleep(0.5)
passwd2 = page.ele('#newPassword2').input(password)
#确认密码
button = page.ele('.ui-button ui-corner-all ui-widget')
if button:
button.click()
else:
print("确定按钮未找到!")
# 点击保存
# time.sleep(1.5)
# elem = page.ele('#btn_accountContainerSaveAccount')
# elem.click() # 点击元素
# Save account
time.sleep(3)
elem = page.ele('xpath://*[@id="btn_accountContainerSaveAccount"]')
if elem is not None:
time.sleep(3)
elem.click()
time.sleep(1)
print("保存按钮已点击")
else:
print("保存按钮未找到!")
print(f"LDAP账号:{spell_name} 密码:{password}")
page.get("www.baidu.com")
#退出浏览器
page.close()
#退出
print("本次注册完成")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化