遍历方式

下行遍历

-
通过循环实现打印
上行遍历

平行遍历

-
所有的平行遍历发生在同一个父亲节点下
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 也可以用于标签的输出
网友评论