如何将文档从 JSOUP 传递到 webview 和 运行 脚本

How to pass document from JSOUP to a webview and run a script

我想使用 jsoup 访问一个网站,但它有一个由脚本评估的保护。我想知道如何获得 ASP.KLR

的值
"ASP.KLR =" + toHex (slowAES.decrypt (c, 2, a, b))

当我发出 Jsoup 请求时,它 returns 以下代码

                  "<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 并获取值,任何想法

你必须解决它。您将通过 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 将是:

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;
  }
}