美文网首页
beautifulsoup 库(二)

beautifulsoup 库(二)

作者: Peng_001 | 来源:发表于2020-07-11 23:08 被阅读0次

    遍历方式

    下行遍历

    • 通过循环实现打印


    上行遍历

    平行遍历

    • 所有的平行遍历发生在同一个父亲节点下


    prettify

    • 利用prettify 为HTML 文本添加换行符。
    >>> print(soup.prettify())
    <html>
     <head>
      <title>
       This is a python demo page
      </title>
     </head>
     <body>
      <p class="title">
       <b>
        The demo python introduces several python courses.
       </b>
      </p>
      <p class="course">
       Python is a wonderful general-purpose programming language. You can learn Python from novice to professional by tracking the following courses:
       <a class="py1" href="http://www.icourse163.org/course/BIT-268001" id="link1">
        Basic Python
       </a>
       and
       <a class="py2" href="http://www.icourse163.org/course/BIT-1001870001" id="link2">
        Advanced Python
       </a>
       .
      </p>
     </body>
    </html>
    >>> 
    
    • prettify 也可以用于标签的输出

    相关文章

      网友评论

          本文标题:beautifulsoup 库(二)

          本文链接:https://www.haomeiwen.com/subject/chruahtx.html