如何使用Jsoup登录此特定页面?

时间:2017-08-01 23:05:43

标签: java login jsoup screen-scraping

我一直在尝试使用 Jsoup 登录此页面https://www.gpro.net/gb/gpro.asp,而我几乎把所有头发拉出来,它只是不起作用。

以下是我一直在尝试的内容:

Connection.Response loginForm = Jsoup.connect("https://www.gpro.net/gb/gpro.asp")
            .method(Connection.Method.GET)
            .execute();

           Document document = Jsoup.connect("https://www.gpro.net/gb/gpro.asp")
            .data("cookieexists", "false")
            .data("Text1", "myEmail")
            .data("Password2", "myPassword")
            .cookies(loginForm.cookies())
            .post();
           System.out.println(document);

这是表格

<form method="post" action="Login.asp?Redirect=gpro.asp" ID="Form1" style="margin:0px">
      <h1>Quick login</h1>
      <div class="inner">

        <label for="textLogin">Username or Email address:</label>
        <input type="text" name="textLogin" value="" class="texty" ID="Text1">
        <label for="textLogin">Password:</label>
        <input type="password" name="textPassword" class="texty" ID="Password2">
        <input type="hidden" name="token" value="" ID="token">
        <input type="hidden" name="Logon" value="Login" ID="Hidden1">
        <input type="submit" name="LogonFake" value="Login" class="halo micro" ID="Submit2">
        <a href="LostPassword.asp" class="password">Forgotten your password?</a>        
        <div class="center" style="clear:both; float:left; width:100%; text-align:center; margin:-3px 0 11px !important;">
            <a class="fb_button fb_button_medium" href="#" onclick="fbLogin()" style="border-radius:6px 6px 6px 6px; display:inlineblock;">
                <span style="border-radius:0 6px 6px 0;  background-clip: padding-box;" class="fb_button_text">Login with Facebook</span>
            </a>
        </div>
        ...

有人可以帮我一把吗? 感谢。

1 个答案:

答案 0 :(得分:1)

您的POST请求参数错误。 工作代码:

    try {
        Connection.Response response = Jsoup.connect("http://www.gpro.net/gb/Login.asp?langCode=gb&Redirect=gpro.asp")
                .method(Connection.Method.POST)
                .data("textLogin", "")  // username
                .data("textPassword", "") // password
                .data("Logon", "Login")
                .execute();

        System.out.println(response.body());
        System.out.println(response.cookies());
    } catch (IOException e) {
        e.printStackTrace();
    }