1. 程式人生 > 其它 >利用python指令碼實現汕頭大學校園的自動登入

利用python指令碼實現汕頭大學校園的自動登入

汕頭大學校園網 python指令碼 wins定時任務

背景

校園網每天都需要自己登入,可以做個自動化

安裝

  1. python3,在命令列可以直接啟動python即算安裝成功
  2. 安裝python庫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. 任務建立結束

完成啦!

就可以自動登入了