栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

登录网站?(Jsoup)

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

登录网站?(Jsoup)

您需要在请求中添加更多参数: csrf,时间,哈希

空表代码:

import org.jsoup.Connection;import org.jsoup.Jsoup;import org.jsoup.nodes.Element;import java.io.IOException;import java.io.UnsupportedEncodingException;import java.nio.charset.StandardCharsets;import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;import java.util.Scanner;public class Quadrigacx {    public static String[] TABLE = new String[]{}; // Add data here    public static void main(String[] args) throws IOException, NoSuchAlgorithmException {        final String URL = "https://www.quadrigacx.com/login/";        String password = "password";        String clientId = "id";        String hashPassword = getHash(new String[]{clientId, password});        Connection.Response response = Jsoup.connect(URL)     .userAgent("Mozilla")     .method(Connection.Method.GET)     .execute();        Element csrf = response.parse().select("input[name=csrf]").first();        Element time = response.parse().select("input[name=time]").first();        Element hash = response.parse().select("input[name=hash]").first();        Jsoup.connect(URL)     .userAgent("Mozilla")     .method(Connection.Method.POST)     .cookies(response.cookies())     .data("password", hashPassword)     .data("client_id", clientId)     .data("csrf", csrf.attr("value"))     .data("time", time.attr("value"))     .data("hash", hash.attr("value"))     .execute();        String googleCode = "";        while (!googleCode.matches("^(?=[0-9]+)\d{6}$")) { System.out.print("Please enter the Two-Factor Authentication to validate your login. (Numbers Only): "); Scanner in = new Scanner(System.in); googleCode = in.nextLine();        }        Jsoup.connect("https://www.quadrigacx.com/authenticate")     .userAgent("Mozilla")     .method(Connection.Method.POST)     .cookies(response.cookies())     .data("google_pre", googleCode)     .data("redirect", "dash")     .data("authenticate", "Authenticate")     .execute();        response = Jsoup.connect("https://www.quadrigacx.com/dash/")     .userAgent("Mozilla")     .cookies(response.cookies())     .method(Connection.Method.GET)     .execute();        System.out.println(response.body());    }    private static String getHash(String[] loginArray) throws NoSuchAlgorithmException, UnsupportedEncodingException {        StringBuilder h = new StringBuilder();        for (String data: loginArray) h.append(data).append(getSalt(data));        MessageDigest digest = MessageDigest.getInstance("SHA-256");        byte[] byteHash = digest.digest(h.toString().getBytes(StandardCharsets.UTF_8));        StringBuilder sb = new StringBuilder(byteHash.length * 2);        for (byte b : byteHash) sb.append(String.format("%02x", b));        return sb.toString();    }    private static String getSalt(String arg) throws UnsupportedEncodingException {        return TABLE[getLastByte(arg)];    }    private static int getLastByte(String login) throws UnsupportedEncodingException {        final byte[] utf8Bytes = login.getBytes("UTF-8");        return utf8Bytes[utf8Bytes.length - 1];    }}

完整的工作代码,您可以在这里找到(很长):

https://pastebin.com/aBf1M3fX



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/454635.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号