基于bs4库HTML的格式输出
如何让<html>页面更友好的显示
prettify()方法:
源代码
import requests
from bs4 import BeautifulSoup
r = requests.get("http://python123.io/ws/demo.html")
demo = r.text
print(demo+'\n')
soup = BeautifulSoup(demo,"html.parser")
print(soup.prettify()+'\n')
soup1 =BeautifulSoup(demo,"lxml")
print(soup1.prettify())
/usr/bin/python3 /home/bliss/python3.5/venv/a测试.py
<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 href="http://www.icourse163.org/c