beautifulsoup4模块
Posted s686zhou
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了beautifulsoup4模块相关的知识,希望对你有一定的参考价值。
Beautifulsoup4模块
简称BS4
from bs4 import BeautifulSoup soup = BeautifulSoup(content,‘html.parser‘) #1.生成一个BeautifulSoup对象 for tag in soup.find_all(): #针对script标签 应该直接删除 if tag.name == ‘script‘: tag.decompose() #将符合条件的标签删除 desc = soup.text[0:150] #截取文章简介 150个文本内容
以上是关于beautifulsoup4模块的主要内容,如果未能解决你的问题,请参考以下文章