医某保服务平台
说明
此项目为Webpack案例
代码实现
spider.py
import requests, execjs, time
cookies = {
'amap_local': '510100',
'yb_header_active': '-1',
}
headers = {
'Accept': 'application/json',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Content-Type': 'application/json',
'Origin': 'https://fuwu.nhsa.gov.cn',
'Pragma': 'no-cache',
'Referer': 'https://fuwu.nhsa.gov.cn/nationalHallSt/',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36',
'X-Tingyun': 'c=B|4Nl_NnGbjwY;x=7b3059fe70ca40d3',
'channel': 'web',
'contentType': 'application/x-www-form-urlencoded',
'sec-ch-ua': '"Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"macOS"',
'x-tif-nonce': 'D8SRNPWZ',
'x-tif-paasid': 'undefined',
'x-tif-signature': 'f0fd5eb8dcdbf6d35834a7f9bba31d4ab97c729510bd5541cedc266eeacc2f57',
'x-tif-timestamp': '1740112310',
# 'Cookie': 'amap_local=510100; yb_header_active=-1',
}
# 读js
js_compile = execjs.compile(open('./main.js', 'r', encoding='utf-8').read())
for page in range(1, 4):
# 调用js加密请求数据,type: str
cipher_req = js_compile.call("encryptReq", page)
response = requests.post(
'https://fuwu.nhsa.gov.cn/ebus/fuwu/api/nthl/api/CommQuery/queryRtalPhacBInfo',
cookies=cookies,
headers=headers,
data=cipher_req,
)
# 调用JS解密
plain_data = js_compile.call("decryptRes", response.json())
items_list = plain_data['list']
# print(items_list)
print(f'Page{page}:')
# 遍历信息
for item in items_list:
print(f"{item['medinsName']} 电话:{item.get('tel')} 地址:{item.get('addr')}")
time.sleep(2)main.js
require('./loader')
u = window.loader('7d92')
function decryptRes(cipher_data) {
plain_data = u.b("SM4", cipher_data)
return plain_data
}
function encryptReq(page) {
let data = {
"transformRequest": {},
"transformResponse": {},
"timeout": 30000,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1,
"headers": {
"common": {
"Accept": "application/json, text/plain, */*"
},
"delete": {},
"get": {},
"head": {},
"post": {
"Content-Type": "application/x-www-form-urlencoded"
},
"put": {
"Content-Type": "application/x-www-form-urlencoded"
},
"patch": {
"Content-Type": "application/x-www-form-urlencoded"
},
"Accept": "application/json",
"Content-Type": "application/json",
"channel": "web"
},
"withCredentials": false,
"baseURL": "/ebus/fuwu/api",
"method": "post",
"url": "/nthl/api/CommQuery/queryRtalPhacBInfo",
"data": {
"addr": "",
"regnCode": "510100",
"medinsName": "",
"businessLvOutMedOtp": "",
"pageNum": page,
"pageSize": 10,
"queryDataSource": "es"
}
}
let cipher_data = u.a(data)
return cipher_data['data']
}
// console.log(decryptRes(cipher_data))loader.js
# Webpack JS 文件
https://fuwu.nhsa.gov.cn/nationalHallSt/app.1736492616509.jsLast updated