码迷,mamicode.com
首页 > 其他好文 > 详细

beautifulsoup4模块

时间:2019-10-06 00:25:31      阅读:69      评论:0      收藏:0      [点我收藏+]

标签:标签   pre   port   from   des   soup   对象   desc   esc   

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模块

标签:标签   pre   port   from   des   soup   对象   desc   esc   

原文地址:https://www.cnblogs.com/s686zhou/p/11625956.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!