Closed rpglover64 closed 8 years ago
How would matchAll
work if you passed different selectors to html
and attr
?
It seems like it may not make sense with different selectors and that you would need something with a type like :: Selectable s => (s -> Scraper str a) -> (s -> Scraper str b) -> s -> Scraper s [(a, b)]
so that you can ensure that you are selecting on the same elements. Of course this doesn't generalize as nicely :/
Another, though less intuitive option, is to abuse chroots
and Any
:
chroots "a" $ do
x <- attr "title" Any
guard (somePredicate x)
html Any
How would
matchAll
work if you passed different selectors tohtml
andattr
?
Presumably, it would return the empty list, since no single element has both selectors.
I hadn't thought of the chroots
trick; I think it should be added to the chroots
documentation, and that may be enough.
Closing out for now, if you feel like the current documentation isn't extensive or visible enough please reopen.
matchAll :: Scraper a b -> Scraper a [b]
, generalizinghtmls
,attrs
,texts
, andchroots
from their singular forms.This is useful in case I want to
matchAll (html "a" <* (attr "title" "a" >>= \x -> guard (somePredicate x)))
.(Yes, I actually ran into this.)
many
doesn't solve the problem because it's alternation;replicateM
and friends don't solve the problem because eachScraper
looks from the current spot.