beautiful soup getting tag.id beautiful soup getting tag.id python python

beautiful soup getting tag.id


You can access tag’s attributes by treating the tag like a dictionary (documentation):

for tag in soup.find_all(class_="bookmark blurb group") :    print tag.get('id')

The reason tag.id didn't work is that it is equivalent to tag.find('id'), which results into None since there is no id tag found (documentation).


This solution lists all tags with ids in a page , It might be helpful too.

tags = page_soup.find_all()for tag in tags:    if 'id' in tag.attrs:        print(tag.name,tag['id'],sep='->')