郭漪亭的作业二

代码


# replace with your code here
from bs4 import BeautifulSoup
import requests
import re
r = requests.get('http://www.jxufe.edu.cn')
html = r.text
soup = BeautifulSoup(html)
text = soup.get_text()
text = re.sub('\n+','\n',text)
text_final = text.replace('\n','')

结果

结果截图

解释

先导入request模块和BeautifulSoup模块,然后建立请求将官网网页打印下来变为html文件,再创建一个BeautifulSoup解析对象,soup.get_text()获取文字内容,最后利用re模块,将多个换行符替换为一个换行符。