Skip to content

Instantly share code, notes, and snippets.

@ergoithz
ergoithz / xpath_soup.py
Last active July 14, 2024 03:56
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.