0

By using beautifulsoup, if I want to use findNext() for n times while n is a variable, how could I achieve it?

.findNext('td').text

Should I use a for loop to achieve it? Let's say I want to find the fifth next td element, how should I change the coding?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Jimmy
  • 1
  • 4

1 Answers1

1

yes, a loop is the way to do it.

el = soup.find("something")
for _ in range(n):
    el = el.findNext('td')
Barmar
  • 741,623
  • 53
  • 500
  • 612