易班网页版简易刷题:湖南商学院教学评估考试

代码没有优化,快的时候十几秒就可以搞定
易班网页版简易刷题:湖南商学院教学评估考试_第1张图片


import time
import xlrd
from selenium import webdriver

def read_excel(row,col):
    # 打开文件
    workbook = xlrd.open_workbook(r'E:\python云沉\湖南教学评估题库.xlsx')
    # 获取所有sheet
    #获取sheet1
    sheet1_name= workbook.sheet_names()[0]
    # 根据sheet索引或者名称获取sheet内容
    sheet2 = workbook.sheet_by_name(sheet1_name)
    merge=str(sheet2.cell(row,col).value)
    return merge


driver=webdriver.Chrome()
driver.get('http://www.yiban.cn/')
try:
    driver.find_element_by_xpath('//*[@id="y-user-account"]/span/a[2]').click()
    driver.find_element_by_id('account-txt').send_keys('账号')
    driver.find_element_by_id('password-txt').send_keys('密码')
    #由于验证码的原因,这里需要手动输入验证码
    time.sleep(1)
    driver.find_element_by_id('login-btn').click()
    time.sleep(18)
    driver.find_element_by_xpath('//*[@id="login-btn"]').click()
except Exception as e:
    print(e)
time.sleep(1)
driver.get('http://www.yooc.me/u/yb')
driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/a[3]').click()
driver.get('https://www.yooc.me/groups')
# 获取打开的多个窗口句柄
windows = driver.window_handles
#切换窗口
driver.switch_to.window(windows[-1])
driver.find_element_by_link_text('我的课群').click()
# driver.get('https://www.yooc.me/dashboard/mygroup')
driver.find_element_by_xpath('//*[@id="join"]/div[3]/div/a[1]').click()

windows = driver.window_handles
#切换窗口
driver.switch_to.window(windows[-1])
driver.maximize_window()
driver.find_element_by_xpath('/html/body/section/section/div[1]/div[4]/a').click()
time.sleep(1)
#下滚动300 防止被挡住
js='document.documentElement.scrollTop =300'
driver.execute_script(js)
try:
    driver.find_element_by_xpath('//*[@id="start-exam"]').click()
    time.sleep(5)
    driver.switch_to_default_content()
    driver.find_element_by_xpath('//*[@id="dlgc-2"]/button').click()
except Exception as e:
    try:
        # time.sleep(20)
        time.sleep(10)
        driver.find_element_by_xpath('/html/body/section/section/div[2]/div[2]/ul/li/div[2]/a').click()
    except Exception as e1:
        pass
#等待刷新
# time.sleep(5)
#窗口聚焦
for i in range(0,45):
    # print(i)
    address=driver.find_elements_by_name(read_excel(i,0))
    # print(address)
    # print(len(address))
    for j in range(2,len(address)+2):
        # str1=time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time()))
        # driver.get_screenshot_as_file('E:\\python云沉\\tp\\'+str1+'.png')
        # print(j-2)
        # print(read_excel(i,j))
        address[j-2].send_keys(read_excel(i,j))
driver.find_element_by_xpath('//*[@id="submit_paper"]').click()
time.sleep(1)
# driver.maximize_window()
driver.find_element_by_xpath('//*[@id="dlgc-2"]/button').click()

湖南商学院教学评估考试题库
链接:https://pan.baidu.com/s/18qTyHLm-d-LbEaL3W0x0GA
提取码:8g40


你可能感兴趣的:(test,python)