gpt4 book ai didi

python - BeautifulSoup 第一个 child 在 thia html 网络抓取

转载 作者:行者123 更新时间:2023-11-30 22:57:50 25 4
gpt4 key购买 nike

我这里有一个示例 html http://cyberrule.netii.net/1.html我想要第一代 child 我已经尝试过了

nav = soup.find( 'nav' )
child_li = nav.findAll("li", { "class" : "dropdown" })

但这一个只给了我带有类下拉列表的列表。列表底部缺失。我想将它们全部放入一个数组中以便逐步处理。

最佳答案

传递recursive=False参数来查找直接子级。

nav = soup.find( 'nav' )
child_li = nav.ul.find_all("li", recursive=False)
for c in child_li:
print c.text

https://www.crummy.com/software/BeautifulSoup/bs4/doc/#the-recursive-argument

关于python - BeautifulSoup 第一个 child 在 thia html 网络抓取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36457418/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com