Amila
Amila

Reputation: 243

web site scraping through Jsoup


I have spent few hours on signing in to web site by using jsoup. But it always gives same login page.
To clarify the issue I tried with facebook site. It also gives same result. Below I mentioned my code

String url ="http://www.facebook.com/";
Document doc;
doc = Jsoup.connect(url)
      .data("email","[email protected]","pass","xyz")
      .userAgent("Mozilla").post();
System.out.println(doc);

can anybody point me where I made a mistake and how can i fix this issue?
In data portion "email" and "pass" are input field id of facebook login page.
Thank you.

Upvotes: 1

Views: 1051

Answers (1)

Martin Revert
Martin Revert

Reputation: 3292

Try this:

String url ="http://www.facebook.com/";
        Document doc;
        doc = Jsoup.connect(url)
        .data("email","[email protected]")
        .data("pass","xyz")
        .userAgent("Mozilla")
        .post();

Anyway, Jsoup is not bad at all, you only need how to use it properly, but also you need to keep in mind that Facebook is expecting a lot more parameters to make a successfull login via POST emulating a web page navigation.

By example:

charset_test
default_persistent
lgnjs
lgnrnd
locale
lsd pass
persistent
timezone

If you need to authenticate and get proper data I suggest that you must give a try to a Facebook SDK for Android:

https://github.com/facebook/facebook-android-sdk/

Upvotes: 4

Related Questions