html目录参数加密,从HTML文件中取出JS加密需要的参数,并调用js内的加密算法

简介这篇文章主要介绍了从HTML文件中取出JS加密需要的参数,并调用js内的加密算法以及相关的经验技巧,文章约2677字,浏览量385,点赞数2,值得参考!

背景,爬虫程序需要模拟登陆,账号密码是经js加密的,加密所需的参数需要从html页面中取出

import javax.script.Invocable;

import javax.script.ScriptEngine;

import javax.script.ScriptEngineManager;

import javax.script.ScriptException;

import java.io.*;

import java.util.regex.Matcher;

import java.util.regex.Pattern;

public class ScriptEngineTest {

public static void main(String[] args) throws IOException, ScriptException, NoSuchMethodException {

ScriptEngineManager manager = new ScriptEngineManager();

ScriptEngine engine = manager.getEngineByName("javascript");

String jsFileName = "src/main/resources/static/ss.js";

String htmlFileName = "src/main/resources/static/url.html";

Pattern pattern = Pattern.compile(""10001", "", "(.*?)"");

String htmldatas = readfile(htmlFileName);

String key = getkey(pattern, htmldatas);

System.out.println("Key=" + key);

FileReader reader = new FileReader(jsFileName);

engine.eval(reader);

if (engine instanceof Invocable) {

Invocable invoke = (Invocable) engine;

String c = (String) invoke.invokeFunction("find", "10001", key, "111111");

System.out.println("加密后:" + c);

}

reader.close();

}

public static String readfile(String filePath) {

File file = new File(filePath);

InputStream input = null;

try {

input = new FileInputStream(file);

} catch (FileNotFoundException e) {

e.printStackTrace();

}

StringBuffer buffer = new StringBuffer();

byte[] bytes = new byte[1024];

try {

for (int n; (n = input.read(bytes)) != -1; ) {

buffer.append(new String(bytes, 0, n, "UTF-8"));

}

} catch (IOException e) {

e.printStackTrace();

}

return buffer.toString();

}

public static String getkey(Pattern pattern, String htmldatas) {

Matcher matcher = pattern.matcher(htmldatas);

String htmldata = "";

String key = "";

if (matcher.find()) {

htmldata = matcher.group();

System.out.println("htmldata=" + htmldata);

String ss[] = htmldata.split(",");

key = ss[2].replace(""","").trim();

}

return key;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值