implementation.element

Module with a converter, to transform any supported node into an appropriate IElement instance. This enables node to be used across soupsavvy with all its features.

to_soupsavvy(node: Any) IElement[source]

Converts node of supported type into an appropriate IElement instance making it usable across soupsavvy with all its features.

Parameters

nodeAny

A node object of supported type, currently supported implementations are: “beautifulsoup4”, “lxml”, “selenium” and “playwright”.

Returns

IElement

An instance of IElement, wrapping the node object.

Examples

>>> from bs4 import BeautifulSoup
... from soupsavvy import to_soupsavvy
... soup = BeautifulSoup("<p>Hello, World!</p>", "html.parser")
... element = to_soupsavvy(soup)

Raises

TypeError

If the node object is of an unsupported type.

Notes

If IElement is passed as an argument, it will be returned back.