天天看點

python搶課_使用python3對學校教務系統進行搶課(一)登陸篇

#coding:utf-8

import urllib

import http.cookiejar    #儲存cookies用到的子產品,不儲存cookies可能無法進行之後的操作

url ="http://192.168.4.17/student/public/login.asp"        #登陸時請求的URL

postdata =urllib.parse.urlencode({

"username":"*******",

"passwd":"*******",

"login":"(unable to decode value)"

}).encode('utf-8')        #這裡時登陸時送出的表單,賬号密碼我手動打碼了,用的時候改一下

header = {

"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"

}        #仿造使用者UA

req = urllib.request.Request(url,postdata,header)        #發送資料包,接受傳回的網頁

##print(urllib.request.urlopen(req).read().decode('utf-8'))

#自動記住cookie

cj = http.cookiejar.CookieJar()

opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))

r = opener.open(req)

print(r.read())