Beautiful Soup库入门

来源:互联网 发布:雪岚数据 编辑:程序博客网 时间:2024/06/06 06:33

bs4库基本元素

Tag Name Attributes NavigatableString Comment

bs4库的遍历功能

.contents .parent .next_sibling

.children .parents .previous_sibling

.descendants .next_siblings .previous_siblings

.find_all(name,attrs,recursive,string,**kwargs)

返回一个列表类型,存储查找的结果

name:对标签名称的检索字符串

attrs:对标签属性值的检索字符串,可标注属性检索

recursive:是否搜索子孙节点

string:

soup.find_all(id="link")

soup.find_all("a","b")

import re

soup.find_all(string = re.compile("python")

tag.find_all()

soup.find_all()