如何将文档从 JSOUP 传递到 webview 并运行脚本
Posted
技术标签:
【中文标题】如何将文档从 JSOUP 传递到 webview 并运行脚本【英文标题】:How to pass document from JSOUP to a webview and run a script 【发布时间】:2021-09-29 03:20:58 【问题描述】:我想使用 jsoup 访问网站,但它具有由脚本评估的保护。我想知道如何获取 ASP.KLR 的值
"ASP.KLR =" + toHex (slowAES.decrypt (c, 2, a, b))
当我发出 Jsoup 请求时,它返回以下代码
"<body>\n" +
" <div class=\"lds-grid\"> \n" +
" <div></div> \n" +
" <div></div> \n" +
" <div></div> \n" +
" <div></div> \n" +
" <div></div> \n" +
" <div></div> \n" +
" <div></div> \n" +
" <div></div> \n" +
" <div></div>\n" +
" </div> \n" +
" <script type=\"text/javascript\" src=\"https://enlineaplus.fcs-tech.com/public/js/aes.min.js\"></script>\n" +
" <script> function toNumbers(d) var e = []; d.replace(/(..)/g, function (d) e.push(parseInt(d, 16)); ); return e; function toHex() for ( var d = [], d = 1 == arguments.length && arguments[0].constructor == Array ? arguments[0] : arguments,e = \"\",f = 0;f < d.length;f++ )e += (16 > d[f] ? \"0\" : \"\") + d[f].toString(16); return e.toLowerCase(); var a = toNumbers(\"d68d69a9a746d20032277ede658ba3ad\"), b = toNumbers(\"58c9e810e2ebcc49ae9ee28af1c6dd53\"), c = toNumbers(\"6cecb0d0211b3c563a23ae1f1b00d5a0\"); document.cookie = \"ASP.KLR=\" + toHex(slowAES.decrypt(c, 2, a, b)) + \"; expires=Session; path=/\";</script>\n" +
" </body>";
我想将该文档传递给 webview 并获取价值,任何想法
【问题讨论】:
【参考方案1】:你必须解决它。您将通过 httpClient 获得该值。我已经在 Flutter 中做到了这一点,只需用你的语言做同样的事情。 如有任何疑问,请写信给电报@ernestoaqs。
var href = AesEncrypt.getLocationHrefFromKLR(response.data.toString());
var a = AesEncrypt.getAFromScriptPage(response.data.toString());
var b = AesEncrypt.getBFromScriptPage(response.data.toString());
var c = AesEncrypt.getCFromScriptPage(response.data.toString());
var klrCookieString = AesEncrypt.getCookieKLR(a, b, c);
那么该类将是:
class AesEncrypt
static final key = encrypting.Key.fromLength(32);
static final iv = encrypting.IV.fromLength(16);
static final encrypter = encrypting.Encrypter(AES(key, mode: AESMode.cbc));
static int _hexToInt(String hex)
int val = 0;
int len = hex.length;
for (int i = 0; i < len; i++)
int hexDigit = hex.codeUnitAt(i);
if (hexDigit >= 48 && hexDigit <= 57)
val += (hexDigit - 48) * (1 << (4 * (len - 1 - i)));
else if (hexDigit >= 65 && hexDigit <= 70)
val += (hexDigit - 55) * (1 << (4 * (len - 1 - i)));
else if (hexDigit >= 97 && hexDigit <= 102)
val += (hexDigit - 87) * (1 << (4 * (len - 1 - i)));
else
throw new FormatException("Invalid hexadecimal value");
return val;
static toNumbers(String texto)
int indexInit = 0;
int indexEnd = 2;
List<int> arr = [];
while (indexEnd <= texto.length)
arr.add(_hexToInt(texto.substring(indexInit, indexEnd)));
indexInit += 2;
indexEnd += 2;
return arr;
static getAFromScriptPage(String html)
String regexStringForA = r'var a = toNumbers\("([a-z0-9]+)"';
RegExp regExpA = new RegExp(regexStringForA);
var matchesA = regExpA.allMatches(html);
var matchA = matchesA.elementAt(0);
return matchA.group(1);
static getBFromScriptPage(String html)
String regexStringForB = r'b = toNumbers\("([a-z0-9]+)"';
RegExp regExpB = new RegExp(regexStringForB);
var matchesB = regExpB.allMatches(html);
var matchB = matchesB.elementAt(0);
return matchB.group(1);
static getCFromScriptPage(String html)
String regexStringForC = r'c = toNumbers\("([a-z0-9]+)"';
RegExp regExpC = new RegExp(regexStringForC);
var matchesC = regExpC.allMatches(html);
var matchC = matchesC.elementAt(0);
return matchC.group(1);
static getLocationHrefFromKLR(String html)
String regexStringForC =
r'location.href[ ]?=[ ]?"([. ?\%\@\#\^\-_\*\=\&a-zA-Z0-9:\/\/]+)';
RegExp regExp = new RegExp(regexStringForC);
var matches = regExp.allMatches(html);
var match = matches.elementAt(0);
return match.group(1);
static getCookieKLR(aa, bb, cc)
var a = toNumbers(aa); // key
var b = toNumbers(bb); // iv
var c = toNumbers(cc); // text
Uint8List key = Uint8List.fromList(a);
Uint8List iv = Uint8List.fromList(b);
Uint8List srcData = Uint8List.fromList(c);
var crypt = AesCrypt();
AesMode mode = AesMode.cbc;
crypt.aesSetKeys(key, iv);
crypt.aesSetMode(mode);
Uint8List decryptedData = crypt.aesDecrypt(srcData);
String result = "";
decryptedData.forEach((element)
if (element.toRadixString(16).length == 1)
result += "0";
result += "$element.toRadixString(16)";
);
return result;
【讨论】:
以上是关于如何将文档从 JSOUP 传递到 webview 并运行脚本的主要内容,如果未能解决你的问题,请参考以下文章
WebView,将本地 .CSS 文件添加到 HTML 页面?
如何将 json 从 JavaScript 传递到 iPad 原生应用程序?
Android - 将 JSON 对象从 webview javascript 传递到 java
如何在 Swift 中从 NSData 显示 PDF - 如何将 PDF 保存到文档文件夹 Swift - 如何在 Swift 中通过 WebView 从保存的 NSData 显示 PDF