From a96ad1b2271bb12a52f13dfd95cdf712927b0172 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sun, 3 Jun 2018 21:33:23 -0500 Subject: [PATCH] html.parser.analyzer: find-classes-named word. --- extra/html/parser/analyzer/analyzer.factor | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/extra/html/parser/analyzer/analyzer.factor b/extra/html/parser/analyzer/analyzer.factor index cf275bcba1..1e004c09ec 100644 --- a/extra/html/parser/analyzer/analyzer.factor +++ b/extra/html/parser/analyzer/analyzer.factor @@ -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 fry html.parser http.client io kernel +locals math math.statistics sequences sets shuffle splitting +unicode urls urls.encoding ; IN: html.parser.analyzer : scrape-html ( url -- response vector ) @@ -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 ;