]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/html/parser/analyzer/analyzer.factor
core: subseq-index? -> subseq-of?
[factor.git] / extra / html / parser / analyzer / analyzer.factor
index cf275bcba1ac97b3a37c8f77e52efb987d3f8d9c..0964b0ad3f2783a5be351bb16f33d40d81038767 100644 (file)
@@ -1,8 +1,9 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors assocs combinators combinators.short-circuit
-fry html.parser http.client io kernel locals math math.statistics
-sequences sets splitting unicode urls urls.encoding shuffle ;
+USING: accessors assocs assocs.extras combinators
+combinators.short-circuit html.parser http.client io kernel math
+math.statistics sequences sets splitting unicode urls
+urls.encoding ;
 IN: html.parser.analyzer
 
 : scrape-html ( url -- response vector )
@@ -141,7 +142,7 @@ ERROR: undefined-find-nth m n seq quot ;
     [ { [ name>> = ] [ closing?>> not ] } 1&& ] with find-all ;
 
 : href-contains? ( str tag -- ? )
-    "href" attribute* [ subseq? ] [ 2drop f ] if ;
+    "href" attribute* [ swap subseq-of? ] [ 2drop f ] if ;
 
 : find-hrefs ( vector -- vector' )
     [ { [ name>> "a" = ] [ "href" attribute? ] } 1&& ] filter sift
@@ -204,3 +205,13 @@ TUPLE: link attributes clickable ;
 : link. ( vector -- )
     [ "href" attribute write nl ]
     [ clickable>> [ bl bl text>> print ] each nl ] bi ;
+
+: find-classes-named ( seq name -- seq' )
+    dupd
+    '[ attributes>> "class" of _ = ] find-all
+    [ find-between ] kv-with { } assoc>map ;
+
+: find-classes-named* ( seq name -- seq' )
+    dupd
+    '[ attributes>> "class" of _ = ] find-all
+    [ find-between* ] kv-with { } assoc>map ;