Getting the nth element using BeautifulSoup

后端 未结 5 1858
生来不讨喜
生来不讨喜 2021-01-31 04:09

From a large table I want to read rows 5, 10, 15, 20 ... using BeautifulSoup. How do I do this? Is findNextSibling and an incrementing counter the way to go?

5条回答
  •  一整个雨季
    2021-01-31 04:24

    You could also use findAll to get all the rows in a list and after that just use the slice syntax to access the elements that you need:

    rows = soup.findAll('tr')[4::5]
    

提交回复
热议问题