Skip to content

Instantly share code, notes, and snippets.

@ergoithz
ergoithz / xpath_soup.py
Last active October 11, 2024 03:23
Generate unique XPATH for BeautifulSoup element
#!/usr/bin/python
# -*- coding: utf-8 -*-
import bs4
def xpath_soup(element):
# type: (typing.Union[bs4.element.Tag, bs4.element.NavigableString]) -> str
"""
Generate xpath from BeautifulSoup4 element.