Skip to content Skip to sidebar Skip to footer

Getting Tag Names With Beautifulsoup

from bs4 import BeautifulSoup source_code = '''ok''' soup = BeautifulSoup(source_code) print soup.a.? #find the object name Using the c

Solution 1:

from bs4 import BeautifulSoup
source_code = """<a href="#" name="linkName"><i><b>ok</b></i></a>"""
soup = BeautifulSoup(source_code)
for tag in soup.findChildren():
    print tag.name

findChildren() function will return a list which possess all the children tag.

[<ahref="#"name="linkName"><i><b>ok</b></i></a>, <i><b>ok</b></i>, <b>ok</b>]

Then iterate the list to get each tag name.

  Output
    aib

Post a Comment for "Getting Tag Names With Beautifulsoup"