BeautifulSoup: get tag name of element itself, not its children
ele is already a tag, try doing this: soup = BeautifulSoup(‘<html><p>line 1</p><div><a>line 2</a></div></html>’) print(soup.find(‘p’).nextSibling.name) So in your example it would be just print(ele.name)