吴诗一的作业二

代码


# from bs4 import BeautifulSoup
import re
import requests
r = requests.get('http://www.jxufe.edu.cn')
html = r.text
soup = BeautifulSoup(html)
text = soup.get_text()#通过函数直接获取标签内文字
text_final = re.sub("\n"," ",text)#将换行符替换为空格

结果

结果截图

解释

BeautifulSoup直接有提取标签文字的功能,直接使用