CSS: Div and Argument Selectors

Viewed 77

I have the following structure,

<div class="main">
    <div id="son" class="well"></div>
    <div id="done" 
    data-ret="512,500"></div>
    </div>

How do I acess the data-ret argument inside div id done? For doing some web scraping.

Tried a couple of ways but don't seem to be able to stick it.

Thanks

1 Answers

Using beautiful soup library:

from bs4 import BeautifulSoup

html = '''<div class="main">
    <div id="son" class="well"></div>
    <div id="done" 
    data-ret="512,500"></div>
    </div>'''

soup = BeautifulSoup(html,"lxml")
data_ret = soup.find("div",{'id':'done'})

print(data_ret['data-ret'])

O/P:

512,500
Related