-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpc9.py
More file actions
36 lines (33 loc) · 919 Bytes
/
Copy pathpc9.py
File metadata and controls
36 lines (33 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
# !/usr/bin/python
import urllib2
import urllib
import cookielib
import re
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
auth_url = 'https://matrix.dean.swust.edu.cn/cas/login'
home_url = 'https://matrix.dean.swust.edu.cn/cas/login';
# 登陆用户名和密码
data={
"username":"20134964",
"password":"210631"
}
# urllib进行编码
post_data=urllib.urlencode(data)
# 发送头信息
headers ={
"Host":"https://matrix.dean.swust.edu.cn",
"Referer": "https://matrix.dean.swust.edu.cn"
}
# 初始化一个CookieJar来处理Cookie
cookieJar=cookielib.CookieJar()
# 实例化一个全局opener
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cookieJar))
# 获取cookie
req=urllib2.Request(auth_url,post_data,headers)
result = opener.open(req)
# 访问主页 自动带着cookie信息
result = opener.open(home_url)
# 显示结果
print result.read()