使用BeautifulSoup获取第n个元素 [英] Getting the nth element using BeautifulSoup
本文介绍了使用BeautifulSoup获取第n个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从一个大表中使用BeautifulSoup读取第5、10、15、20 ...行.我该怎么做呢?是findNextSibling和递增计数器吗?
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?
推荐答案
您还可以使用findAll
获取列表中的所有行,然后使用切片语法访问所需的元素:>
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]
这篇关于使用BeautifulSoup获取第n个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文