1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import requests
from bs4 import BeautifulSoup #引入BeautifulSoup类

url = "https://python123.io/ws/demo.html"

r = requests.get(url)

print(r.status_code)

print("\n")

#demo = r.text #html格式信息

#soup = BeautifulSoup(demo,"html.parser")#使用html.parser对demo进行html解析
soup = BeautifulSoup(open(r"C:\Users\Administrator\Desktop\beautifulsoup\demo.html"))
print(soup.prettify())

BeautifulSoup官方文档