No docs apparently (and unfortunately), but I suppose you can get a feel
for what the words do by looking at the source + tests.  That's what I've
done to give you this reply, anyhow.  :-)

I'm not sure how you were invoking the word before to not see the desired
behavior---I'm guessing probably on a raw HTML string, like

```
"<html><body><div class=\"foo\"><p>bar</p></div></body></html>"
"foo" find-by-class
```

which results in a cryptic error.  It turns out the word is actually
supposed to be called on a vector of `tag` tuples, which you can generate
using the `parse-html` word from html.parser:

```
IN: scratchpad "<html><body><div
class=\"foo\"><p>bar</p></div></body></html>" parse-html
"foo" find-by-class

--- Data stack:
2
T{ tag f "div" H{ ~array~ } f f }
```

Because it uses `find`, this leaves two values on the stack: the index of
the element, and the element itself---a `tag` instance.
http://docs.factorcode.org/content/word-find,sequences.html

To find *every* tag with the given class, there's apparently no predefined
word.  But I do spy a `find-all` helper:

```
IN: scratchpad "<html><body><div class=\"foo\"><p
class=\"foo\">bar</p></div></body></html>" parse-html
[ "class" attribute "foo" = ] find-all .
{
    {
        2
        T{ tag
            { name "div" }
            { attributes H{ { "class" "foo" } } }
        }
    }
    {
        3
        T{ tag
            { name "p" }
            { attributes H{ { "class" "foo" } } }
        }
    }
}
```

In general, I'm not sure if html.parser is very mature compared to, say,
the XML vocab: http://docs.factorcode.org/content/article-xml.html

```
IN: scratchpad "<html><body><div class=\"foo\"><p
class=\"foo\">bar</p></div></body></html>" string>xml
"foo" "class" deep-tags-with-attr children-tags [
    "Found: " write xml>string print
] each
Found: <div class="foo"><p class="foo">bar</p></div>
Found: <p class="foo">bar</p>
```

But there are some answers anyway.

Hope that helps,
--Alex Vondrak

On Sun, Jul 14, 2013 at 3:52 PM, Mark Green <m...@antelope.nildram.co.uk>wrote:

> Hi,
>
> Is there any documentation for find-by-class in html.parser.analyzer? I'm
> not sure what it does. It doesn't seem to search for elements with a given
> value in the class attribute and I'm not sure how it would return them
> anyway (is it a filter?)
>
> Thanks!
>
>
>
> ------------------------------------------------------------------------------
> See everything from the browser to the database with AppDynamics
> Get end-to-end visibility with application monitoring from AppDynamics
> Isolate bottlenecks and diagnose root cause in seconds.
> Start your free trial of AppDynamics Pro today!
> http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to