Skip to content

Instantly share code, notes, and snippets.

@guffyWave
Created May 10, 2017 18:00
Show Gist options
  • Save guffyWave/2a86c8570825bac4f6988d7db53a0efc to your computer and use it in GitHub Desktop.
Save guffyWave/2a86c8570825bac4f6988d7db53a0efc to your computer and use it in GitHub Desktop.
compile 'org.jsoup:jsoup:1.10.2'
Document doc;
try {
doc = Jsoup.connect("https://jsoup.org/").followRedirects(true).get();
// doc=Jsoup.parse(new File("/home/gufran/Desktop/JSoupStudy/StumbleUpon - StumbleUpon.html"),null);
// get title of the page
String title = doc.title();
System.out.println("Title: " + title);
// get all links
// Elements links = doc.select("a[href]");
// for (Element link : links) {
// // get the value from href attribute
// System.out.println("\nLink : " + link.attr("href"));
// System.out.println("Text : " + link.text());
// }
Elements el = doc.select("div.col2");
for (Element link : el) {
System.out.println("\nData : " + link);
System.out.println("Text : " + link.text());
}
} catch (IOException e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment