How can I check if a Tag
element is of a certain type, for example a div
, in BS3?
You are looking for the tag name:
if element.name == 'div':
Demo:
>>> from bs4 import BeautifulSoup
>>> soup = BeautifulSoup('<div><span></span></div>')
>>> print soup.find('div').name
div
This attribute hasn't changed between BeautifulSoup 3 and 4. I strongly recommend you use BeautifulSoup 4; all development on BS3 has stopped, the last release for that version was over 2 years ago.