1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| if __name__ == "__main__": try: chrome_options = Options() chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-dev-shm-usage') chrome_options.add_argument('--headless') stu = [ {'id': 'xxxxx', 'pw': 'xxxxx', 'email_to': 'xxxxx@foxmail.com'}, ] for stu_dic in stu: test = VisitSogouByIE() driver = webdriver.Chrome(options=chrome_options) driver.get('http://xsc.sicau.edu.cn/SPCP/Web/') driver.implicitly_wait(20) get_code(driver) captcha = code_rec() while True: try: if len(captcha) < 4: driver.refresh() time.sleep(2) get_code(driver) captcha = code_rec() else: login(driver, captcha, stu_dic) time.sleep(5) is_exist = test.isElementPresent( driver=driver, by='id', value='platfrom2') if not is_exist: if not test.isElementPresent(driver=driver, by='id', value='layui-m-layer0'): break driver.back() time.sleep(2) driver.refresh() time.sleep(2) get_code(driver) captcha = code_rec() print("登陆失败!") elif is_exist: print("登陆成功!") break except Exception as erro: print(erro) captcha = 'xxx' continue time.sleep(2) is_sub = sub_form(driver) if is_sub: text = "恭喜您!打卡成功!" if is_sub == '当前采集日期已登记!': text = is_sub send_email(text, stu_dic) elif not is_sub: print("打卡失败!稍后重试!") text = "打卡失败!稍后重试!" send_email(text, stu_dic) text = "程序运行结束,所有STU均已操作一遍!" send_email(text, stu[0]) except BaseException as E: me = {'id': 'xxxx', 'pw': 'xxxx', 'email_to': 'xxxx@foxmail.com'} print(E) print("程序意外终止!") text = "程序意外终止!" send_email(text,me)
|