Created
April 30, 2014 16:02
-
-
Save mikaelhg/4c1543ecfdd88362f46b to your computer and use it in GitHub Desktop.
Java 8 lambda streams come in handy when parsing HTML with Jsoup and Lombok @builders
This file contains 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
Document doc = Jsoup.parse(...); | |
doc.select("form#login").stream() | |
.map(e -> e.attr("action")) | |
.map(action -> find(action, LINK_ID_PATTERN).group(1)) | |
.filter(Objects::nonNull) | |
.findFirst() | |
.ifPresent(builder::id); | |
content.select("div#datePublished").stream() | |
.map(Element::text) | |
.map(SiteScraper::parseLocalDateTime) | |
.filter(Optional::isPresent).map(Optional::get) | |
.findFirst().ifPresent(builder::published); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment