2013-04-28 90 views
0

如何使用Jsoup登錄InvestorsHub?Java - 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(); 
+0

哪條線失敗?有些例外或者什麼都沒有發生? – WindRider 2013-04-28 22:29:13

回答

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(); 
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();