python爬虫之BeautifulSoup4介绍

CSS 选择器:BeautifulSoup4

四大对象种类

  1. Tag

  2. NavigableString

  3. BeautifulSoup

  4. Comment

遍历文档树

  1. 直接子节点 :.contents .children 属性

  2. 所有子孙节点: .descendants 属性

  3. 节点内容: .string 属性

搜索文档树

  1.find_all(name, attrs, recursive, text, **kwargs)

  2. CSS选择器

 (1)通过标签名查找

 (2)通过类名查找

 (3)通过 id 名查找

 (4)组合查找

 (5)属性查找

   (6) 获取内容

猜你喜欢

转载自www.cnblogs.com/python-kp/p/12625195.html
今日推荐