File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -52,7 +52,35 @@ If you are using the W3CDom class (and the various inner classes), you may also
5252
5353## Examples:
5454
55- ### Parse, select and print all title from HN
55+
56+
57+ ### Parse, select and print all titles from lobste.rs
58+
59+ ``` java
60+ package ch.digitalfondue.jfiveparse.example ;
61+
62+ import ch.digitalfondue.jfiveparse.* ;
63+
64+ import java.io.IOException ;
65+ import java.io.InputStreamReader ;
66+ import java.io.Reader ;
67+ import java.net.URI ;
68+ import java.nio.charset.StandardCharsets ;
69+
70+ public class LoadLobsters {
71+
72+ public static void main (String [] args ) throws IOException {
73+ try (Reader reader = new InputStreamReader (URI . create(" https://lobste.rs/" ). toURL(). openStream(), StandardCharsets . UTF_8 )) {
74+ NodeMatcher<Node > matcher = Selector . parseSelector(" span[role=heading] a.u-url" );
75+ JFiveParse . parse(reader). getAllNodesMatchingAsStream(matcher)
76+ .map(Element . class:: cast)
77+ .forEach(a - > System . out. printf(" %s [%s]\n " , a. getTextContent(), a. getAttribute(" href" )));
78+ }
79+ }
80+ }
81+ ```
82+
83+ ### Parse, select and print all titles from HN
5684
5785``` java
5886package ch.digitalfondue.jfiveparse.example ;
You can’t perform that action at this time.
0 commit comments