Currently, grouping is done by specifying the group
parameter.
@select(selector="...", group="<group-selector>")
@select(selector="...", group="<group-selector>")
def handler(element):
return {"<key>": "<value-extracted-from-element>"}
This is alright for Playwright because it is smart enough to identify the selector but for other parsers like BeautifulSoup4, lxml (not implemented - #38) and Parsel (not implemented - #33). There is no easy way to distinguish the type of selector used for grouping.
By introducing a new @group()
decorator, we can specify the type using any available arguments, css
, xpath
, text
, regex
or just selector
(Playwright does not really need the other options).
@group(css="<group-selector>")
@select(selector="...")
@select(selector="...")
def handler(element):
return {"<key>": "<value-extracted-from-element>"}
The @group()
decorator also prevents repeating the same group parameter on each @select()
decorator.
The group
parameter in @select()
decorator will be retained and can be used to override the @group()
decorator only for that specific rule. It will not affect other @select()
decorators.
Limitations to implement:
- There should be only one
@group()
decorator per function. Throw an error or overwrite it in a "group rule" list based on the precedence of using multiple decorators in Python.