把网页课程ID转换一行带","隔开的数据
上代码
for a in range(30):
# 点击查询
driver.find_element_by_xpath('//*[@id="UserInfo"]/thead/tr[2]/td[6]/div/button[1]').click()
time.sleep(3)
# 定义数组
umn = []
for j in range(3):
for i in range(1, 21):
try:
t = driver.find_element_by_xpath('//*[@id="UserInfo"]/tbody/tr[{}]/td[1]'.format(i)).text
except Exception:
break
time.sleep(0.2)
umn.append(t)
umn.append(",")
# 点击第2页
try:
driver.find_element_by_xpath('//*[@id="UserInfo_wrapper"]/div[3]/div[1]/div[1]/div/a[2]/i').click()
time.sleep(2)
except Exception:
break
print(umn)
time.sleep(2)
# 切换到声网页
driver.get("http://aclassroomadmin-uat.acadsoc.com.cn/TeacherInfo/AgoraNetlessCourseLessonIndex")
time.sleep(1)
# 点击批量创建
driver.find_element_by_xpath('//*[@id="BatchAdd"]').click()
time.sleep(0.5)
# 把课程ID填入
driver.find_element_by_xpath('//*[@id="input_clids"]').send_keys(umn)
time.sleep(2)
# 点击创建
driver.find_element_by_xpath('//*[@id="submit"]').click()
while True:
try:
alert = driver.switch_to.alert # 进入警告框,得到警告框对象
alert.accept() # 点击确认
print("今天课程已全部转声网,感谢你的使用!!")
# 清空课程ID
umn.clear()
except Exception:
print('课程正在转换中')
time.sleep(2)
else:
break