-
Notifications
You must be signed in to change notification settings - Fork 0
/
xyw2.py
48 lines (36 loc) · 1.26 KB
/
xyw2.py
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
37
38
39
40
41
42
43
44
45
46
47
48
from bs4 import BeautifulSoup
import urllib.request
import http.cookiejar
import urllib.parse
def get_cookie(USERNAME, PASSWD):
LOGIN_URL = "http://auth.bupt.edu.cn/authserver/login?service=http%3a%2f%2fyjxt.bupt.edu.cn%2fULogin.aspx"
cookiejar = http.cookiejar.LWPCookieJar(USERNAME)
cookiehandle = urllib.request.HTTPCookieProcessor(cookiejar)
httphandle = urllib.request.HTTPHandler()
opener = urllib.request.build_opener(cookiehandle, httphandle)
html = opener.open(LOGIN_URL)
soup = BeautifulSoup(html.read().decode("utf-8"),'lxml')
lt_node = soup.find(nameislt)
lt = lt_node['value']
exec_node = soup.find(nameisexecution)
exec_str = exec_node['value']
data = {
'lt': lt,
'username': USERNAME,
'password': PASSWD,
'execution': exec_str,
'_eventId': 'submit',
'rmShown': '1'
}
opener.open(LOGIN_URL,urllib.parse.urlencode(data).encode())
return cookiejar
def nameislt(tag):
if tag.has_attr('name')and tag['name'] == 'lt':
return True
else:
return False
def nameisexecution(tag):
if tag.has_attr('name')and tag['name'] == 'execution':
return True
else:
return False