Beautifulsoup4: how to get a list of class name for a specific tag

I get this from beautifulsoup4:

<tr class="Details"> <td class=" s-12-to-15 ">ABC</td> <td class="s-15-to-18 ">DEF</td> <td class=" s-18-to-21 ">GHI</td></tr>

How can I get:

s-12-to-15 ABC
s-15-to-18 DEF
s-18-to-21 GHI

I looked through the bf4 documentation and a few questions about loading the class name, but to no avail. I can not find this class. (I know that I can parse the string to get the result, but I'm interested in learning about bf4).

-1
source share
1 answer
for s in soup.find_all('td'):
    print ''.join(s['class']).strip(), s.text
+1
source

All Articles