-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathGetAPI.py
135 lines (124 loc) · 4.21 KB
/
GetAPI.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# encoding:utf-8
'''
author: sixseven
topic: 爬取裁判文书网
date: 2018-04-17
contact: [email protected]
modified: ztcooper
2018-04-24
contact: [email protected]
github: ztcooper
获得API数据
'''
import requests
from urllib import parse
import execjs
from random import choice
from settings import Settings
class GetAPI(object):
def __init__(self):
self.session = requests.Session()
self.s = Settings().setting
self.sc = Settings().shortcut
self.u = Settings().user_agents
def get_guid(self):
# 获取guid参数
js1 = '''
function getGuid() {
var guid = createGuid() + createGuid() + "-" + createGuid() + "-" + createGuid() + createGuid() + "-" + createGuid() + createGuid() + createGuid(); //CreateGuid();
return guid;
}
var createGuid = function () {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}
'''
ctx1 = execjs.compile(js1)
guid = (ctx1.call("getGuid"))
return guid
def get_number(self, guid):
# 获取number
codeUrl = "http://wenshu.court.gov.cn/ValiCode/GetCode"
data = {
'guid': 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': choice(self.u),
}
req1 = self.session.post(codeUrl, data=data, headers=headers)
number = req1.text
return number
def get_vjkl5(self, guid, number, Param):
# 获取cookie中的vjkl5
shortcut = self.sc["%s" % Param.split(":")[0]]
url1 = "http://wenshu.court.gov.cn/list/list/?sorttype=1&number=" + number + \
"&guid=" + guid + "&conditions=searchWord+" + shortcut + "++" + \
parse.quote(Param)
Referer1 = url1
headers1 = {
"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": choice(self.u),
}
req1 = self.session.get(url=url1, headers=headers1, timeout=10)
try:
vjkl5 = req1.cookies["vjkl5"]
return vjkl5
except:
return self.get_vjkl5(guid, number, Param)
def get_vl5x(self, vjkl5):
# 根据vjkl5获取参数vl5x
js = ""
fp1 = open('./sha1.js')
js += fp1.read()
fp1.close()
fp2 = open('./md5.js')
js += fp2.read()
fp2.close()
fp3 = open('./base64.js')
js += fp3.read()
fp3.close()
fp4 = open('./vl5x.js')
js += fp4.read()
fp4.close()
ctx2 = execjs.compile(js)
vl5x = (ctx2.call('vl5x', vjkl5))
return vl5x
def get_data(self, Param, Index, Page, Order, Direction):
guid = self.get_guid()
number = self.get_number(guid)
vjkl5 = self.get_vjkl5(guid, number, Param)
vl5x = self.get_vl5x(vjkl5)
# 获取数据
url2 = "http://wenshu.court.gov.cn/List/ListContent"
headers2 = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.8",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Host": "wenshu.court.gov.cn",
"Origin": "http://wenshu.court.gov.cn",
"Proxy-Connection": "keep-alive",
# "Referer":Referer1,
"User-Agent": choice(self.u),
"X-Requested-With": "XMLHttpRequest"
}
data = {
"Param": Param,
"Index": Index,
"Page": Page,
"Order": Order,
"Direction": Direction,
"vl5x": vl5x,
"number": number,
"guid": guid
}
req2 = self.session.post(url=url2, headers=headers2, params=data)
return req2.text