0

Trying to parse this html:

    </thead>
    <tbody>
                        <tr>
            <td class="rank">
                1.
            </td>
            <td class="name">
                                            <a href="https://hoopshype.com/player/stephen-curry/salary/">
                        Stephen Curry                           </a>
                                    </td>
                                    <td style="color:black" class="hh-salaries-sorted" data-value="40231758">
                    $40,231,758                     </td>

How do I pull "color:black" from here?

AdamA
  • 343
  • 1
  • 2
  • 11
  • extract the style attribute as you would with a dictionary. There are lots of answers to this on stackoverflow to guide you. E.g. https://stackoverflow.com/questions/2612548/extracting-an-attribute-value-with-beautifulsoup – QHarr Dec 03 '19 at 07:14
  • Does this answer your question? [Extracting an attribute value with beautifulsoup](https://stackoverflow.com/questions/2612548/extracting-an-attribute-value-with-beautifulsoup) – QHarr Dec 03 '19 at 07:15
  • 1
    Thank you @QHarr, very similar to the below answer. When I was searching initially I didn't catch this entry - – AdamA Dec 03 '19 at 21:21

1 Answers1

1
from bs4 import BeautifulSoup
data = """
    </thead>
    <tbody>
                        <tr>
            <td class="rank">
                1.
            </td>
            <td class="name">
                                            <a href="https://hoopshype.com/player/stephen-curry/salary/">
                        Stephen Curry                           </a>
                                    </td>
                                    <td style="color:black" class="hh-salaries-sorted" data-value="40231758">
                    $40,231,758                     </td>
"""

soup = BeautifulSoup(data, 'html.parser')

for item in soup.findAll('td', attrs={'class': 'hh-salaries-sorted'}):
    print(item.get('style'))

Output:

color:black