windows下实现校园网自动登陆

windows下实现校园网自动登陆

需求
校园网经常会断开连接,每次都要重新登录,windows定时任务自动登录校园网
思路
1.python脚本检测网络是否连接,如果没网络,实现校园网账号密码自动登录
2.将脚本加入windows任务计划程序中,定时启动

实现过程
1.下载Chrome浏览器以及chromedriver(和chrome版本一致)
chrome各个版本下载地址
http://npm.taobao.org/mirrors/chromedriver/
https://chromedriver.storage.googleapis.com/index.html
将chrome加入环境变量(C:\Users\HP\AppData\Local\Google\Chrome\Application)
在这里插入图片描述

2.python代码 (C:/lss/autologin/auto_login.py)

#-*- coding:utf8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
import os,subprocess

username = "102111153"
password = "1207371X"
url = "http://202.114.177.246/srun_portal_pc?ac_id=1&theme=pro"

def isNotConnecting():
    # 0 表示有网 1 2表示错误
    res = subprocess.call("ping www.baidu.com",shell=True) 
    return True if res else False

def Signon():
    driver = webdriver.Chrome()
    driver.get(url)
    # 通过使用选择器选择到表单元素进行模拟输入和点击按钮提交
    driver.find_element(By.ID, 'username').click()
    driver.find_element(By.ID, 'username').clear()
    driver.find_element(By.ID, 'username').send_keys(username)

    driver.find_element(By.ID, 'password').click()
    driver.find_element(By.ID, 'password').clear()
    driver.find_element(By.ID, 'password').send_keys(password)

    driver.find_element(By.ID, 'login-account').click()
    # 退出窗口
    driver.close()

if __name__ == "__main__":
    if isNotConnecting():
        Signon()

3.将脚本加入windows定时任务
在这里插入图片描述

更改用户为“SYSTEM”,为了让脚本每次自动执行时,不会有cmd以及浏览器弹出来影响工作
步骤:名称=>更改用户或组=>高级=>立即查找
在这里插入图片描述
在这里插入图片描述

查看python路径

import sys
print(sys.path)

在这里插入图片描述

C:\Users\HP\AppData\Local\Programs\Python\Python310\python.exe
C:/lss/autologin/auto_login.py
在这里插入图片描述

最后,右键该列任务,可以立即运行,然后查看运行结果。
在这里插入图片描述

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值