delahug Wrote:for cell in row.find_all('td',data-ending_ = 'RPR'):
Can not add data-ending
_
= 'RPR' for this attribute,here have to use dictionary in search.
it work for class attribute class
_
="rp-horseTable__spanNarrow"
Quick test.
from bs4 import BeautifulSoup
html = '''\
<td class="rp-horseTable__spanNarrow" data-ending="RPR" data-test-selector="full-result-rpr">85<!----</td>'''
soup = BeautifulSoup(html, 'lxml')
Usage test:
>>> td_tag = soup.find('td')
>>> td_tag.attrs
{'class': ['rp-horseTable__spanNarrow'],
'data-ending': 'RPR',
'data-test-selector': 'full-result-rpr'}
# Search with data-ending
td_tag = soup.find('td', {'data-ending': 'RPR'})
<td class="rp-horseTable__spanNarrow" data-ending="RPR" data-test-selector="full-result-rpr">85</td>
# Search with class
td_tag = soup.find('td', class_="rp-horseTable__spanNarrow")
<td class="rp-horseTable__spanNarrow" data-ending="RPR" data-test-selector="full-result-rpr">85</td>
# Get text and attributes
>>> td_tag.text
'85'
>>>
>>> td_tag.get('data-ending')
'RPR'
>>> td_tag.get('class')
['rp-horseTable__spanNarrow']