代码拉取完成,页面将自动刷新
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("本次注册完成")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。