尝试使用jsoup登录

时间:2012-09-27 22:15:29

标签: jsoup http-authentication

我登录网站(我知道因为代码的结果显示我在:“Dilema Veche Contul meuLogoutÎntreb?ri frecvente ...等)成功但我无法浏览网站的链接登录后,似乎没有保留cookie或其他什么。有什么建议吗?谢谢。

公共课艺术{ public static void main(final String [] args)抛出IOException {

Response res = Jsoup.connect("http://pay.dilemaveche.ro/autentificare/?redirect=http%3A%2F%2Fdilemaveche.ro%2F%2F&return=true").data("username", "myusername", "password", "mypassword").method(Method.POST).execute();


Map <String, String> cookies = res.cookies();
Document doc = Jsoup.connect("http://pay.dilemaveche.ro/autentificare/?redirect=http%3A%2F%2Fdilemaveche.ro%2F%2F&return=true").cookies(cookies).get();
Elements bck = doc.select("li.first").select("a[href]:contains(Dilema Veche)");
String str = bck.attr("abs:href");
Document doc0 = Jsoup.connect(str).cookies(cookies).get();
System.out.println(doc.text());
}

}

1 个答案:

答案 0 :(得分:0)

登录网站需要很多步骤,这取决于网站处理cookie的方式。现在大多数大型网站都使用自定义cookie策略,而Jsoup cookie的处理程序非常通用。我不认为JSoup是一个很好的选择,但是你可以使用JSoup在你拥有cookie时解析HTML。我建议你试试HttpClient或URLConnection,特别是HttpClient。祝你好运!

相关问题