cookie還是不太懂,登陸了教務處主頁後,查成績用的另一個header,所以總是登陸超時
import urllib.parse,urllib.request,http.cookiejar,os
#cookie處理,照抄
cookie = http.cookiejar.CookieJar()
cookieProc = urllib.request.HTTPCookieProcessor(cookie)
opener = urllib.request.build_opener(cookieProc)
urllib.request.install_opener(opener) #全局的opener
postdata=urllib.parse.urlencode({
'systemId':'',
'xmlmsg':'',
'userName':'012130494XXXX',
'password':'012130494XXXX',
'type':'xs',
'imageField.x':'60',
'imageField.y':'19'
}).encode(encoding='UTF8')
#似乎是在header帶入了驗證,所以只能照抄
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0',
'Host':'sso.jwc.whut.edu.cn',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Referer':'http://sso.jwc.whut.edu.cn/Certification/toLogin.do',
'Cookie':'JSESSIONID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
'Connection':'keep=alive'
}
req = urllib.request.Request(
url = 'http://sso.jwc.whut.edu.cn/Certification/login.do',
data = postdata,
headers = headers
)
result = urllib.request.urlopen(req).read().decode("utf-8")
print(result)
os.system('pause')