Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save documentprocessing/d958ad73b5910caee160c55bbe6e147d to your computer and use it in GitHub Desktop.

Select an option

Save documentprocessing/d958ad73b5910caee160c55bbe6e147d to your computer and use it in GitHub Desktop.
Use CSS selectors to find elements with jsoup API
File input = new File("input.html");
Document doc = Jsoup.parse(input, "UTF-8", "https://some-website.com/");
Elements links = doc.select("a[href]"); // a with href
Elements pngs = doc.select("img[src$=.png]");
// img with src ending .png
Element masthead = doc.select("div.masthead").first();
// div with class=masthead
Elements resultDivs = doc.select("h3.r > div");
// direct div after h3
Elements resultAs = resultDivs.select("a");
// A elements within resultDivs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment