Closed Caellian closed 8 months ago
I'd like to add that if we do this, I would argue that they should be functions (because they don't need to macros) and they should return iterators over ElementRef
instead of NodeRef
, i.e. their implementation should use ElementRef::wrap
, e.g.
self.children().filter_map(ElementRef::wrap)
their implementation should use
ElementRef::wrap
Thanks, that's better. Updated the issue.
I don't like how scraper requires me to check whether each node is an element while I'm traversing the tree when all I want to do is traverse elements. 70% of the time tree traversion occurs on
Element
, and there's very few convenience methods for doing so.For instance, a very common case where you'd like to select the first element child of an element requires:
because
head_row.first_child()
might be a Text node.Suggestion
I suggest adding convenience methods for traversal which would significantly reduce this boilerplate: