你的浏览器不支持canvas

安静 是一种风骨

PyExecJS爬取js加密数据

Date: Author: 吕雄

本文章采用 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议 进行许可。转载请注明来自吕雄

函数调取过程:

getData()——getAQIData() 和 getWeatherData() ——反混淆 ——getServerData() 加密,反混淆得出——getParam()、decodeData()

import execjs
import requests
# Init environment
node = execjs.get()
 
# Params
method = 'GETCITYWEATHER'
city = '昆明'
type = 'HOUR'
start_time = '2019-09-10 00:00:00'
end_time = '2019-09-10 23:00:00'
 
# Compile javascript
file = 'encryption.js'
ctx = node.compile(open(file).read())
print(ctx)
#params = ctx.eval("getEncryptedData",)
#Get params
js = 'getEncryptedData("{0}", "{1}", "{2}", "{3}", "{4}")'.format(method, city, type, start_time, end_time)
params = ctx.eval(js)

# Get encrypted response text
api = 'https://www.aqistudy.cn/apinew/aqistudyapi.php'
response = requests.post(api, data={'d': params})

# Decode data
js = 'decodeData("{0}")'.format(response.text)
decrypted_data = ctx.eval(js)

原文链接:JavaScript加密逻辑分析与Python模拟执行实现数据爬取


墨染半纸,清心煮字...