共计 829 个字符,预计需要花费 3 分钟才能阅读完成。
#coding:utf-8
import urllib
import http.cookiejar
uname="用户名"
pword="密码"
url = "https://einstein.enoctus.co.uk/dologin.php"
postdata =urllib.parse.urlencode({
'username': uname,
'password': pword
}).encode('utf-8')
header = {
"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Encoding":"utf-8",
"Accept-Language":"zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3",
"Connection":"keep-alive",
"Host":"einstein.enoctus.co.uk",
"Referer":"https://einstein.enoctus.co.uk/clientarea.php",
"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0"
}
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().decode('utf-8'))
正文完