#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())