Skip to content

Commit e80967c

Browse files
committed
update readme with another example
1 parent 9c51670 commit e80967c

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff 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
5886
package ch.digitalfondue.jfiveparse.example;

0 commit comments

Comments
 (0)