[英]Java - JSoup log in InvestorsHub
How do you login to InvestorsHub using Jsoup? 您如何使用Jsoup登录到InvestorsHub?
I tried the following with no success... 我尝试了以下操作,但没有成功...
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();
Sometimes, it helps first getting the the form itself before doing the post. 有时,它有助于在完成发布之前先获取表单本身。
Try something like that (not tested): 尝试类似的事情(未经测试):
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();
Something like this ( working solution ) 这样的东西( 有效的解决方案 )
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.