BeautifulSoup: Get the class text

You could use the following:

content = '''
<div class="value">
<p class="name">Michael Jordan</p>
</div>

<div class="value">
<p class="team">Real Madrid</p>
</div>

<div class="value">
<p class="Sport">Ping Pong</p>
</div>
'''

from bs4 import BeautifulSoup

soup = BeautifulSoup(content)

person = {}

for div in soup.findAll('div', {'class': 'value'}):
    person[div.find('p').attrs['class'][0]] = div.text.strip()

print(person)

Output

{'Sport': u'Ping Pong', 'name': u'Michael Jordan', 'team': u'Real Madrid'}

You can do iit like this:

for data in soup.findAll('div',{'class':'value'}):
    person = {}
    for item in data.find_all('div'):
        attr = item.p.attrs.get("class")[0]
        value = item.p.text
        person[attr] = value

    print person