Code Monkey home page Code Monkey logo

srun_autologin_selenium's Introduction

Srun_AutoLogin_Selenium

深澜软件校园网自动登录(基于Selenium的Python脚本,国科大中关村宿舍区测试)

背景

日常需要远程访问宿舍的电脑,但宿舍的深澜校园网时不时自动登出,导致断网影响使用。

目标

周期性检测深澜校园网的登录状态,一旦断联,自动登录。

AutoLogin2UCAS.py功能

  1. 判断登录页面的状态
    • 如果页面有“登录”按钮,即有id为login-account的网页元素,判定为未登录状态
    • 如果页面有“注销”按钮,即有id为logout的网页元素,判定为已登录状态
    • 等待网页加载的时间为3s,超过3s没有结果则判定超时
  2. 如果登录页面处在未登录状态,自动填写用户名(username)和密码(password),点击登录(login-account)按钮

使用方法

  1. 安装Python,配置环境变量
    • 不详述
  2. 安装selenium包(用于模拟浏览器)和pyinstaller包(用于打包exe)
    • Win+RcmdEnter
    • pip3 install selenium
    • pip3 install pyinstaller
  3. 修改python脚本
    • 下载AutoLogin2UCAS.py到本地
    • 使用记事本打开AutoLogin2UCAS.py
    • 替换第13/14行的xxxxxxxx/xxxxxxxx为你的登录账号/密码
    • 第9行的URL是登录页面网址,视情况修改
    • 第17行指定浏览器,如果电脑没有Chrome可以替换为
      • Edge浏览器:driver = webdriver.Edge()
      • FireFox浏览器:driver = webdriver.FireFox()
  4. 将修改后的python脚本打包成exe文件
    • 到AutoLogin2UCAS.py的本地目录下,在地址栏直接输入cmdEnter
    • pyinstaller -F -w AutoLogin2UCAS.py
    • 然后在当前目录下会产生几个文件和文件夹,打开dist文件夹,其中AutoLogin2UCAS.exe就是我们需要的可执行文件
      02 after_pyinstaller.png
      03 dist_exe.png
  5. 在任务计划程序中创建任务,周期性执行AutoLogin2UCAS.exe
    • 打开任务计划程序:Win+Rtaskschd.mscEnter
    • 点击右侧栏的“创建任务…”
      04 taskschd_0.png
    • 参照下列截图设置任务:
      05 taskschd_1.png
      06 taskschd_2.png
      07 taskschd_3.png
      08 taskschd_4.png
      09 taskschd_5.png

补充说明

  • 根据我的经验,每次“登录”或“注销”后会有几秒到几十秒的时间无法加载出登录页面。如果你按照以上的截图设置了任务,那等一两分钟就好了。
  • 不认识“地址栏”的看下图:
    01 cmd_currentDir.png

srun_autologin_selenium's People

Contributors

ding998 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.