1

In the following kind of HTML table's columns, I can't get the numeric values under the quotation marks with the find_all('td')[i].text command. Python returns me blank values instead of 3.03, 1.21, etc... Please can someone help me catching those values?

<td class="table-main__odds colored" data-oid="5lmp0xv464x0xf55p3"><span><span><span data-odd="3.03"></span></span></span></td>
<td class="table-main__odds colored" data-oid="5lmp3xv464x0xf55p9"><span><span><span data-odd="1.21"></span></span></span></td>
<td class="table-main__odds" data-odd="3.23" data-oid="5lmovxv464x0xf55p1"></td>
find_all('td')[i].text ---> Output : blank vaues
HedgeHog
  • 22,146
  • 4
  • 14
  • 36
Dave85
  • 21
  • 3

1 Answers1

0

.text won't work cause, the expected values are no texts. Select all the elements by its attribute (data-odd) and extract the value:

for e in soup.select('[data-odd]'):
    print(e.get('data-odd'))

-> 3.03
   1.21
   3.23

or only from <span>

for e in soup.select('span[data-odd]'):
    print(e.get('data-odd'))

-> 3.03
   1.21

Example

from bs4 import BeautifulSoup

html = '''
<td class="table-main__odds colored" data-oid="5lmp0xv464x0xf55p3"><span><span><span data-odd="3.03"></span></span></span></td>
<td class="table-main__odds colored" data-oid="5lmp3xv464x0xf55p9"><span><span><span data-odd="1.21"></span></span></span></td>
<td class="table-main__odds" data-odd="3.23" data-oid="5lmovxv464x0xf55p1"></td>

'''

soup = BeautifulSoup(html)

for e in soup.select('[data-odd]'):
    print(e.get('data-odd'))
HedgeHog
  • 22,146
  • 4
  • 14
  • 36