MCPcopy Create free account
hub / github.com/EZ-hwh/AutoScraper / get_absolute_xpath

Function get_absolute_xpath

utils/html_utils.py:41–58  ·  view source on GitHub ↗

Given an HTML string and an XPath expression, returns the absolute XPath of the element. :param html: HTML content as a string :param xpath: XPath expression as a string :return: Absolute XPath string or None if not found

(html, xpath)

Source from the content-addressed store, hash-verified

39 return html_content
40
41def get_absolute_xpath(html, xpath):
42 """
43 Given an HTML string and an XPath expression, returns the absolute XPath of the element.
44 :param html: HTML content as a string
45 :param xpath: XPath expression as a string
46 :return: Absolute XPath string or None if not found
47 """
48 try:
49 tree = etree.HTML(html)
50 node = tree.xpath(xpath)
51 if not node:
52 return None
53 if isinstance(node, list):
54 node = node[0]
55 return build_absolute_xpath(node)
56 except Exception as e:
57 print(f"Error: {e}")
58 return None
59
60def build_absolute_xpath(node):
61 """

Callers 1

html_utils.pyFile · 0.85

Calls 1

build_absolute_xpathFunction · 0.85

Tested by

no test coverage detected