zoukankan      html  css  js  c++  java
  • find_all的用法 Python(bs4,BeautifulSoup)

    find_all()简单说明:

    find_all()

    find_all() 方法搜索当前tag的所有tag子节点,并判断是否符合过滤器的条件

    用法一:

    rs=soup.find_all('a')
    

    将返回soup中所有的超链接内容

    类似的还有rs.find_all('span')、rs.find_all('title')、rs.find_all('h1')

    也可加入查找条件,eg:

    rs.find_all('img',{'class':'news-img'})
    

    将返回所有的class属性为news-img的img内容

    用法二:

    这里的true指的就是选中所有有id这个属性的标签

    soup.find_all(id=True)
    

    返回结果:

      [<a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>, # <a class="sister" href="http://example.com/lacie" id="link2">Lacie</a>, # <a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>]

    用法三:

    soup.find_all("a", string="Elsie")
    

    通过 string 参数可以搜搜文档中的字符串内容.与 name 参数的可选值一样, string 参数接受 字符串 , 正则表达式 , 列表, True

    用法四:

    soup.find_all("a", limit=2)
    

    limit即为查找的数量,此处查找数量为两次

  • 相关阅读:
    mysql 常用函数
    JSP 分页代码
    day15(Mysql学习)
    day14(编码实战-用户登录注册)
    Bootstrap第3天
    Bootstrap第2天
    Bootstrap 第一天
    day13(JSTL和自定义标签&MVC模型&javaweb三层框架)
    label 对齐
    Alert提示框之后跳转指定页面
  • 原文地址:https://www.cnblogs.com/yizhixiang/p/11869595.html
Copyright © 2011-2022 走看看