Created
May 27, 2025 15:25
-
-
Save documentprocessing/d958ad73b5910caee160c55bbe6e147d to your computer and use it in GitHub Desktop.
Use CSS selectors to find elements with jsoup API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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