comparison tests/reddit.ur @ 21:7275f59cab61

tagAOR and a Reddit example of using it
author Adam Chlipala <adam@chlipala.net>
date Sat, 29 Sep 2012 10:30:00 -0400
parents
children 923e097e9ba3
comparison
equal deleted inserted replaced
20:dd5b333a7960 21:7275f59cab61
1 fun main () =
2 doc <- Feed.fetch "http://www.reddit.com/?limit=30";
3
4 acc <- Feed.app' (Feed.tree (Feed.tagAOR "div" {DataUps = "data-ups", Class = "class"} {Style = "style"})
5 (Feed.tagAO "a" {Class = "class", Style = "style", Href = "href"}))
6 (fn (div, a) (count, list) =>
7 return (case a.Href of
8 None => (count, list)
9 | Some link =>
10 if count >= 30
11 || not (String.isPrefix {Full = div.Class, Prefix = " thing "})
12 || Option.isSome (String.sindex {Haystack = div.Class, Needle = "promoted"})
13 || div.Style = Some "display:none"
14 || a.Class <> Some "title "
15 || a.Style = Some "display:none" then
16 (count, list)
17 else
18 (count + 1, link :: list)))
19 doc (0, []);
20
21 return <xml><body>
22 <h1>Top 30 Reddit Links</h1>
23
24 <ol>
25 {List.mapX (fn url => <xml><li>{[url]}</li></xml>) (List.rev acc.2)}
26 </ol>
27 </body></xml>