Constructs an absolute XPath expression for a given node. :param node: A lxml node for which to build the XPath :return: A string representing the absolute XPath to the node
(node)
| 58 | return None |
| 59 | |
| 60 | def build_absolute_xpath(node): |
| 61 | """ |
| 62 | Constructs an absolute XPath expression for a given node. |
| 63 | :param node: A lxml node for which to build the XPath |
| 64 | :return: A string representing the absolute XPath to the node |
| 65 | """ |
| 66 | parts = [] |
| 67 | while node is not None and isinstance(node, _Element) and node.tag != 'html': |
| 68 | parent = node.getparent() |
| 69 | siblings = [sib for sib in parent.iterchildren() if sib.tag == node.tag] |
| 70 | count = siblings.index(node) + 1 |
| 71 | parts.insert(0, f"{node.tag}[{count}]") |
| 72 | node = parent |
| 73 | return '/html/' + '/'.join(parts) |
| 74 | |
| 75 | def simplify_html(html, reserve_attrs = ['class']): |
| 76 | soup = BeautifulSoup(html, 'html.parser') |
no outgoing calls
no test coverage detected