How to use Jsoup with Volley?

Can anyone write/link a simple example using volley and jsoup? Under the hood, Jsoup make use of HttpUrlConnection. This class has known unresolved issues, bugs and performance issues on the Android Platform. Instead, load the data with Volley first then parse it with Jsoup. Sample Code: private static RequestQueue myRequestQueue = null; public Document GetDocument(String … Read more

Sending POST request with username and password and save session cookie

Assuming that the HTML form look like below: <form action=”http://example.com/login” method=”post”> <input type=”text” name=”username” /> <input type=”password” name=”password” /> <input type=”submit” name=”login” value=”Login” /> </form> You can POST it and obtain cookies as below: Response response = Jsoup.connect(“http://example.com/login”) .method(Method.POST) .data(“username”, username) .data(“password”, password) .data(“login”, “Login”) .execute(); Map<String, String> cookies = response.cookies(); Document document = response.parse(); … Read more

Jsoup Cookies for HTTPS scraping

I know I’m kinda late by 10 months here. But a good option using Jsoup is to use this easy peasy piece of code: //This will get you the response. Response res = Jsoup .connect(“url”) .data(“loginField”, “[email protected]”, “passField”, “pass1234”) .method(Method.POST) .execute(); //This will get you cookies Map<String, String> cookies = res.cookies(); //And this is the … Read more

Parse JavaScript with jsoup

Since jsoup isn’t a javascript library you have two ways to solve this: A. Use a javascript library Pro: Full Javascript support Con: Additional libraray / dependencies B. Use Jsoup + manual parsing Pro: No extra libraries required Enough for simple tasks Con: Not as flexible as a javascript library Here’s an example how to … Read more

JSoup UserAgent, how to set it right?

You might try setting the referrer header as well: doc = Jsoup.connect(“https://www.facebook.com/”) .userAgent(“Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6”) .referrer(“http://www.google.com”) .get();