自己查了一下校園網點擊鏈接后調出瀏覽器認證頁面的機制叫 potral 具體介紹:https://blog.csdn.net/xianweijian/article/details/49450703
反正太復雜我是看不懂,那就簡單暴力點:1,把跳出的瀏覽器進程kill掉 2,用爬蟲實現自動登陸。
首先用cmd命令選擇校園網:
netsh wlan connect name=i-NUIST
注意:如果這時候直接用爬蟲登陸,還來不及連上網絡,所以先暫停一秒再運行,同理 先運行殺死程序時可能edge還未跳出,總之具體順序是:打開wifi——等待一秒——自動登陸——跳出瀏覽器——殺死瀏覽器
打開網絡監聽器fiddler

獲取請求headers和登陸網站名
再獲得請求表單,這里密碼是已經加密過的,我一開始以為是全校通用密碼123321,結果沒反應。。
用requests庫post方法登陸。
這時potral會跳出瀏覽器界面讓你認證,直接killtask(這里會跳出默認瀏覽器 我把edge設成默認以為chrome可能有別的頁面以免被殺)
TASKKILL /F /IM MicrosoftEdge.exe #/F指要殺死的程序 #IM 指程序名
然后就ok了~run it 一鍵登陸完成
源碼
1 import requests 2 import os 3 import time 4 5 def openwifi(): 6 os.system('netsh wlan connect name=i-NUIST') 7 time.sleep(1) 8 9 def killtask(): 10 os.system('TASKKILL /F /IM MicrosoftEdge.exe ') 11 12 def login(): 13 thedata={'domain':'CMCC', 14 'enablemacauth':'0', 15 'password':'xxxx', 16 'username':'batt1ebear' 17 } 18 theheader={ 19 'Host': 'a.nuist.edu.cn', 20 'User-Agent':'Mozilla/5.0 (X11; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0', 21 'Accept': 'application/json, text/javascript, */*; q=0.01', 22 'Accept-Language':'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3', 23 'Accept-Encoding': 'gzip, deflate', 24 'Content-Type': 'application/x-www-form-urlencoded', 25 'X-Requested-With':'XMLHttpRequest', 26 'Referer':'http://a.nuist.edu.cn/index.php?url=aHR0cDovL2RldGVjdHBvcnRhbC5maXJlZm94LmNvbS9zdWNjZXNzLnR4dA==', 27 'Content-Length': '67', 28 29 'Cookie':'_gscu_1147341576=059821653286gq10; sunriseUsername=123441534;\ 30 sunriseDomain=NUIST;sunriseRememberPassword=true; sunrisePassword=123456;\ 31 PHPSESSID=hb0o9bkct2f6ge164oj3vj0me5;think_language=zh-CN', 32 'Connection':'keep-alive', 33 } 34 35 url="http://a.nuist.edu.cn/index.php/index/login" 36 p=requests.post(url,data=thedata,headers=theheader) 37 38 39 def main(): 40 openwifi() 41 login() 42 killtask()
os.exit(0) 43 44 main()
