In questo articolo vedremo come ottenere i contenuti HTML di un elemento con BeautifulSoup in Python.
Possiamo usare il metodo encode_contents()
che restituisce una sequenza di byte che possiamo convertire in stringa con il metodo decode()
.
def bs_innerhtml(bs_element=None):
if bs_element is None:
return None
html_bytes = bs_element.encode_contents()
return html_bytes.decode()