This repository has been archived by the owner on Apr 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparameter.py
90 lines (77 loc) · 2.62 KB
/
parameter.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import random
import execjs
from urllib import parse
from session import Session
from error import NetworkException
class Parameter:
def __init__(self, param: str, sess: Session):
self.sess = sess
self.param = param
with open('./js/vl5x.js') as f:
js = f.read()
self.js_vl5x = execjs.compile(js)
self.guid = self._guid()
self.number = self._number()
self.vjkl5 = self._vjkl5(param)
self.vl5x = self._vl5x()
def refresh(self):
self.guid = self._guid()
self.number = self._number()
@staticmethod
def _guid():
"""
生成GUID
"""
def create_guid():
return str(hex((int(((1 + random.random()) * 0x10000)) | 0)))[3:]
return '{}{}-{}-{}{}-{}{}{}'.format(
create_guid(), create_guid(),
create_guid(), create_guid(),
create_guid(), create_guid(),
create_guid(), create_guid()
)
def _number(self):
"""
获取Number
"""
code_url = "http://wenshu.court.gov.cn/ValiCode/GetCode"
data = {
'guid': self.guid
}
headers = {
'Host': 'wenshu.court.gov.cn',
'Origin': 'http://wenshu.court.gov.cn',
'Referer': 'http://wenshu.court.gov.cn/',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': self.sess.user_agent
}
r = self.sess.post(url=code_url, data=data, headers=headers)
return r.text
def _vjkl5(self, param):
"""
获取Cookies中的vjkl5
"""
url = "http://wenshu.court.gov.cn/list/list/?sorttype=1&number=" + self.number \
+ "&guid=" + self.guid \
+ "&conditions=searchWord+QWJS+++" + parse.quote(param)
# referer = url
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.8",
"Host": "wenshu.court.gov.cn",
"Proxy-Connection": "keep-alive",
"Upgrade-Insecure-Requests": "1",
"User-Agent": self.sess.user_agent
}
retry_time = 5
while retry_time > 0:
r = self.sess.get(url=url, headers=headers)
try:
vjkl5 = r.cookies["vjkl5"]
return vjkl5
except:
retry_time -= 1
raise NetworkException('Cannot find vjkl5 in cookies.')
def _vl5x(self):
return self.js_vl5x.call('GetVl5x', self.vjkl5)