校园网认证脚本
作者:互联网
适用于铁皮大学
软件测试上学了selenium的使用,于是想到用selenium写一个校园网自动认证的程序,减少打开浏览器填写密码费时费力
能直接运行的可执行文件已上传至GitHub,无需python环境即可点击运行,使用nuikta打包(pyinstall依赖老导不进来
项目地址:Arisf0617/std-connection: 石铁大校园网自动登录,使用python+selenium (github.com)
from selenium import webdriver import os def read(): i = 0 try: f = open("STD.ini", encoding='utf-8') line = f.readline() list = ['', '', ''] while line: list[i] = line.split('=')[1].replace('\n', '') line = f.readline() i = i + 1 f.close() except Exception as e: print("配置文件错误") print("except:", e) return list list = read() try: browser = webdriver.Edge(executable_path=list[0],capabilities={"ms:edgeOptions": { 'args': ['--headless', '--disable-gpu' ]}}) except Exception as e: print("驱动错误", format(e)) os._exit(0) try: browser.get("http://1.1.1.1") name = browser.find_element_by_xpath('/html/body/form/div[1]/div[2]/div[1]/div/div[2]/input') password = browser.find_element_by_xpath('/html/body/form/div[1]/div[2]/div[1]/div/div[3]/input') except Exception as e: print("已经连接到网络") print("except:", e) browser.quit() os._exit(0) else: name.send_keys(list[1]) password.send_keys(list[2]) browser.find_element_by_xpath('/html/body/form/div[1]/div[2]/div[1]/div/div[5]/button').click() finally: try: alert = browser.find_elements_by_xpath('/html/body/div[4]/div[4]/button') except Exception as e: print('登录失败', format(e)) try: messages = browser.find_element_by_xpath('/html/body/div[3]/div[2]') try: for message in messages: assert '账号或密码不正确' in message.text print('登录失败') except Exception as e: print('账号或密码不正确', format(e)) except Exception as e: print('登录成功', format(e)) finally: browser.quit() os._exit(0)
标签:脚本,list,except,认证,try,print,校园网,div,browser 来源: https://www.cnblogs.com/Arisf/p/16194647.html