-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsl.py
67 lines (53 loc) · 1.86 KB
/
jsl.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
# =======================
# --*-- coding: utf-8 --*--
# @Time : 2022/7/27
# @Author : 微信公众号:K哥爬虫
# @FileName: jsl.py
# @Software: PyCharm
# =======================
import json
import re
import requests
import execjs
import shlex
import sys
cookies = {}
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"
}
#url = "https://www.mps.gov.cn/index.html"
url2 = "https://www.cnvd.org.cn/patchInfo/show/429181"
url = cmdline = " ".join(map(shlex.quote, sys.argv[1:]))
def get_first_cookie():
global cookies
resp_first = requests.get(url=url, headers=headers)
# 获取 cookie 值 __jsluid_s
cookies.update(resp_first.cookies)
# 获取第一层响应内容, AAEncode 加密
content_first = re.findall('cookie=(.*?);location', resp_first.text)[0]
jsl_clearance_s = execjs.eval(content_first).split(';')[0]
# 获取 cookie 值 __jsl_clearance_s
cookies['__jsl_clearance_s'] = jsl_clearance_s.split("=")[1]
def get_second_cookie():
global cookies
# 通过携带 jsluid_s 和 jsl_clearance_s 值的 cookie 获取第二层响应内容
resp_second = requests.get(url=url, headers=headers, cookies=cookies)
# 获取 go 字典参数
go_params = re.findall(';go\((.*?)\)</script>', resp_second.text)[0]
params = json.loads(go_params)
return params
def get_third_cookie():
with open('jsl.js', 'r', encoding='utf-8') as f:
jsl_js = f.read()
params = get_second_cookie()
# 传入字典
third_cookie = execjs.compile(jsl_js).call('cookies', params)
cookies.update(third_cookie)
def main():
get_first_cookie()
get_third_cookie()
resp_third = requests.get(url=url, headers=headers, cookies=cookies)
resp_third.encoding = 'utf-8'
print(resp_third.text)
if __name__ == '__main__':
main()