利用python脚本实现汕头大学校园的自动登录

背景

校园网每天都需要自己登录,可以做个自动化

安装

  1. python3,在命令行可以直接启动python即算安装成功,记住安装路径,后面需要用到
  2. 安装python库requests
    # 镜像安装requests
    pip install -i https://pypi.tuna.tsinghua.edu.cn/simple requests

python脚本

这是来自于网络上的智慧,

 1 # USE PYTHON TO LOGIN SCHOOL NET
 2 # After fill in your account and password, just 'python login.py' directly, then the network will login automatically.
 3 # If you can not import requests, please try - pip install requests
 4 import requests
 5 
 6 headers = {
 7     'Accept': '*/*',
 8     'Accept-Encoding': 'gzip,deflate,br',
 9     'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,ja;q=0.7',
10     'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
11     'X-Requested-With': 'XMLHttpRequest',
12     'Referer': 'https://a.stu.edu.cn:444/ac_portal/20170602150308/pc.html?template=20170602150308&tabs=pwd&vlanid=0&_ID_=0&switch_url=&url='
13 }
14 
15 data = {
16     'opr'         : 'pwdLogin',
17     'userName'    : '14bxye', # Fill in your school account here, for example: 'userName':'14bxye'
18     'pwd'         : '123456', # Fill in your school account password here,for example: '123456'.
19     'ipv4or6'     : '',
20     'rememberPwd' : '0',
21 }
22 
23 url = 'https://a.stu.edu.cn:444/ac_portal/login.php'
24 
25 login = requests.post(url, data = data, headers = headers, verify = False)

脚本运行效果

 

 

注意

要将python脚本保存在一个无中文或中文符号的路径下

定时任务

  1. 打开文件资源管理器,右键“此电脑”,点击“管理”

     

     

  2. 也可以直接搜索“计算机管理”进入

     

     

  3. 找到任务,创建任务

     

     

  4. 开始,下面是具体的任务内容,命名

     

     

  5. 启动的频率与时间点

     

     

     

  6. 关联python.exe和自动登录python脚本

     

     

  7. 其他的“条件、设置”可以不做编辑

     

     

  8. 任务创建结束

     

     

完成啦!

就可以自动登录了

 

posted @ 2022-01-10 18:16  何时悠长假期  Views(377)  Comments(0Edit  收藏  举报