0

您如何使用 Jsoup 登录 InvestorsHub?

我尝试了以下但没有成功...

    res = Jsoup.connect("https://investorshub.advfn.com/boards/login.aspx").data("ctl00_CP1_LoginView1_Login1_UserName", "Myusername", "ctl00_CP1_LoginView1_Login1_Password", "Mypassword").method(Method.POST).execute();
    Map<String, String> loginCookies = res.cookies();
    doc = Jsoup.connect("link to the page").cookies(loginCookies).get();
4

2 回答 2

1

有时,在发布之前先获取表单本身会有所帮助。

尝试类似的东西(未测试):

    res = Jsoup.connect("https://investorshub.advfn.com/boards/login.aspx").get();

    res = Jsoup.connect("https://investorshub.advfn.com/boards/login.aspx").data("ctl00_CP1_LoginView1_Login1_UserName", "Myusername", "ctl00_CP1_LoginView1_Login1_Password", "Mypassword").method(Method.POST).cookies(res.cookies()).execute();
    Map<String, String> loginCookies = res.cookies();
    doc = Jsoup.connect("link to the page").cookies(loginCookies).get();
于 2013-04-29T06:00:39.273 回答
0

像这样的东西(工作解决方案

String loginURL = "https://investorshub.advfn.com/boards/login.aspx"

Connection.Response response = Jsoup.connect(loginURL)
        .method(Connection.Method.GET)
        .execute();

Document loginPage = response.parse();

Document document = Jsoup.connect(loginURL)
        .data("ctl00$CP1$LoginView1$Login1$UserName", "Myusername")
        .data("ctl00$CP1$LoginView1$Login1$Password", "Mypassword")
        .data("ctl00$CP1$LoginView1$Login1$LoginButton", "Log In")
        .data("__VIEWSTATE", loginPage.getElementById("__VIEWSTATE").val())
        .cookies(response.cookies())
        .post();   
于 2013-04-29T16:25:51.547 回答