AlphaWolf
AlphaWolf

Reputation: 405

Python beautiful soup find content in class

I got a html like this:

<div class="row" data-keywordid="53707903">
     <div class="kw-table-cell kw-keyword-name-cell">
     </div>
</div>

In normal case i can take content inner of class "row" by using: soup.find("div",{"class": "row"}) but what i want is get the data-keywordid and value of that 53707903. I have no idea for it. Have anyway to get it? Thanks !

Upvotes: 0

Views: 407

Answers (1)

Quinn Weber
Quinn Weber

Reputation: 927

from bs4 import BeautifulSoup

text = ''''
    <div class="row" data-keywordid="53707903">
     <div class="kw-table-cell kw-keyword-name-cell">
     </div>
    </div>
'''

soup = BeautifulSoup(text, "html.parser")

a = soup.find('div')

a.attrs['data-keywordid']

Upvotes: 1

Related Questions