You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Notice that there is a massive html.select(Selector::parse("...").unwrap()) block for pretty much everything. Since this is so common, it should have a more compact version. Some examples of implementations are:
// macroselect!(html, selector)// -> Result<Select<'a, 'b>, SelectorErrorKind<'_>>// a top-level functionfnselect_from(html:&Html,selector:&str) -> Result<Select<'a,'b>,SelectorErrorKind<'_>>;// method of html
html.try_select(selector:&str) -> Result<Select<'a,'b>,SelectorErrorKind<'_>>
The text was updated successfully, but these errors were encountered:
Approximately-Equal
changed the title
Provide Additional 'select!` Macro for Improved Readability
Provide additional 'select!` macro for improved readability
Jan 20, 2025
I think most of the line noise is Selector::parse("..").unwrap() and we should not encourage using selectors parsed on the fly, i.e. it is often much more efficient to parse selectors once and store them for reuse. So I would argue that a
fnselector(selectors:&str) -> Selector<'_>;
is preferable as it encourages that avoids the need for a macro.
Also note that free functions and methods to directly select items will not work as proposed AFAIU as the Select iterators borrow from the Selector values, so even the macro would have to inject a binding into the enclosing scope to keep the selector alive while the iterator is used. Alternatively, the function/methods would need to use a closure to access the selection iterator, e.g.
A common use case is to use scraper to scrape many selections of some Html page and store them. For example:
Notice that there is a massive
html.select(Selector::parse("...").unwrap())
block for pretty much everything. Since this is so common, it should have a more compact version. Some examples of implementations are:This would make the
Stats
look likeThis decreases line width by 15 characters and makes it easier to read the exact selection at a glance.
The text was updated successfully, but these errors were encountered: