D
D
Danila Belyy2022-03-30 16:03:54
beautiful soup
Danila Belyy, 2022-03-30 16:03:54

How to get the content of data-tooltip through BeautifulSoup?

Let's say we have this html code:

<tr class="gray">
    <td class="p1" ....</td>
    ......
    <td class="p3">
        <div data-tooltip='QWERTY' class='ToolTip'>12345</div>
    </td>

How to get the contents of data-tooltip to get QWERTY on the output? Python language.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2022-03-30
@danila_belyy

I'm not sure if this is the most direct way, but something like this is possible:

from bs4 import BeautifulSoup

data = '''
    <td class="p3">
        <div data-tooltip='QWERTY' class='ToolTip'>12345</div>
    </td>'''
soup = BeautifulSoup(data,'html.parser')
div = soup.find('div')  # тут вы уж сами найдите нужный вам div, я просто моделирую типа мы его нашли. 
tag = 'data-tooltip'
print(div.attrs[tag])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question