Если вы используете [0]
, то вы получите только первый элемент. Чтобы получить второй элемент, используйте [1]
Или используйте for
-l oop для работы со всеми элементами
text = '''<div class ="table">
<table class="stats">
<td>Not this</td>
</table>
<table class="stats">
<td>I want this</td>
</table>
</div>'''
from bs4 import BeautifulSoup as BS
soup = BS(text, 'html.parser')
containers = soup.findAll("table", {"class":"stats"})
container = containers[0]
rows = container.findChildren(['td'])
print('1st:', rows)
container = containers[1]
rows = container.findChildren(['td'])
print('2nd:', rows)
print('--- for-loop ---')
for container in containers:
print(container.findChildren(['td']))
print('-')
Результат
1st: [<td>Not this</td>]
2nd: [<td>I want this</td>]
--- for-loop ---
[<td>Not this</td>]
-
[<td>I want this</td>]
-