课程视频地址:
https://edu.csdn.net/course/detail/28645

搜索文档树find_all方法-recursive参数
recursive参数
文档内容如下:
html_doc = “”"

The Dormouse's story

The Dormouse's story

Once upon a time there were three little sisters; and their names were Elsie, Lacie and Tillie; and they lived at the bottom of a well.

...

"""

调用tag的find_all()方法时,Beautiful Soup会检索当前tag的所有子孙节点,如果只想搜索tag的直接子节点,可以使用参数recursive=False。

【四二学堂】搜索文档树find_all方法-recursive参数
【四二学堂】搜索文档树find_all方法-recursive参数

标签在 标签下, 但并不是直接子节点, 标签才是直接子节点。在允许查询所有后代节点时 Beautiful Soup 能够查找到 <title> 标签。但是使用了recursive=False参数之后,只能查找直接子节点,这样就查不到 <title> 标签了。

相关文章: