def getElementsBy(start_node: ParentNode,
cond: Callable[['Element'], bool]) -> NodeList:
"""Return list of child elements of start_node which matches ``cond``.
``cond`` must be a function which gets a single argument ``Element``,
and returns boolean. If the node matches requested condition, ``cond``
should return True.
This searches all child elements recursively.
:arg ParentNode start_node:
:arg cond: Callable[[Element], bool]
:rtype: NodeList[Element]
"""
elements = []
for child in start_node.children:
if cond(child):
elements.append(child)
elements.extend(child.getElementsBy(cond))
return NodeList(elements)
评论列表
文章目录