beautifulsoup4模块

时间:2020-05-12 09:02:11   收藏:0   阅读:53

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个文本内容

原文:https://www.cnblogs.com/zhukaijian/p/12873486.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!