ben890
ben890

Reputation: 1133

Beautifulsoup getting attributes following class name

I'll preface this by saying I'm relatively new to beautiful soup. I understand that the following line:

soup.find_all('div', class_ = 'favorite_links')[0] 

will get me the entire contents of the first div tag where class = favorite-links. However what I actually want is text that is immediately to the right of the class name:

    <div class="favorite-links" data-can-favorite="" data-id="10820653">
</div>

What I hope to get is the numbers after data-id. Is there a way to do this? I could definitely do it using string operations but I want to know whether there is a way to do this specifically using BeautifulSoup

Sorry in advance for my poor terminology. As I said before I'm relatively new to BeautifulSoup.

Thanks!

Upvotes: 0

Views: 52

Answers (1)

eLRuLL
eLRuLL

Reputation: 18799

soup.find_all('div', class_="favorite-links")[0]['data-id']

Upvotes: 1

Related Questions