-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReq.py
65 lines (50 loc) · 2.17 KB
/
Req.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
__author__ = "Hua777"
__copyright__ = "Copyright 2018, Hua777"
__version__ = "2.0"
__email__ = "[email protected]"
import requests as REQ
from bs4 import BeautifulSoup as BS
Year = 1071
Urls = {
'index': 'http://selcrs.nsysu.edu.tw/',
'menu4': 'http://selcrs.nsysu.edu.tw/menu4/',
'check': 'http://selcrs.nsysu.edu.tw/menu4/Studcheck.asp',
'valid': 'http://selcrs.nsysu.edu.tw/validcode.asp',
'selected': 'http://selcrs.nsysu.edu.tw/menu4/query/slt_result.asp',
'search': 'http://selcrs.nsysu.edu.tw/menu1/dplycourse.asp',
'menu': 'http://selcrs.nsysu.edu.tw/menu4/Studfun.asp',
'step2': 'http://selcrs.nsysu.edu.tw/menu4/addcourse/ssprs.asp'
}
Encoding = 'big5'
Proxies = {
'http': 'https://208.97.119.150:55509',
'https': 'https://208.97.119.150:55509'
}
Headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
}
def CheckUrl(url_key):
return Urls[url_key] if url_key in Urls else url_key
def Session():
return REQ.Session()
def SessGetBS(sess, url_key, params = None, headers = Headers, stream = False):
return BS(SessGet(sess, url_key, params).text, 'html.parser')
def SessPostBS(sess, url_key, data = None, headers = Headers, stream = False):
return BS(SessPost(sess, url_key, data).text, 'html.parser')
def SessGet(sess, url_key, params = None, headers = Headers, stream = False):
req = sess.get(CheckUrl(url_key), headers = headers, params = params, stream = stream, timeout = 10)
req.encoding = Encoding
return req
def SessPost(sess, url_key, data = None, headers = Headers, stream = False):
req = sess.post(CheckUrl(url_key), headers = headers, data = data, stream = stream, timeout = 10)
req.encoding = Encoding
return req
def Get(url_key, params = None, headers = Headers):
req = REQ.get(CheckUrl(url_key), headers = headers, params = params, timeout = 10)
req.encoding = Encoding
return req.text
def Post(url_key, data = None, headers = Headers):
req = REQ.post(CheckUrl(url_key), headers = headers, data = data, timeout = 10)
req.encoding = Encoding
return req.text