我是靠谱客的博主 甜蜜服饰,最近开发中收集的这篇文章主要介绍python is beautiful_python BeautifulSoup基本用法,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

#coding:utf-8

importosfrom bs4 importBeautifulSoup#jsp 路径

folderPath = "E:/whm/google/src_jsp"

for dirPath,dirNames,fileNames inos.walk(folderPath):for fileName infileNames:if fileName.endswith(".jsp"):

soup=BeautifulSoup(open(os.path.join(dirPath,fileName)),"html.parser")if(soup.header is notNone):

soup.header.extract()#属性选择器。。。只能选择出第一个符合规则的元素

if(soup.find(attrs={‘role‘:‘banner‘}) is notNone):

soup.find(attrs={‘role‘:‘banner‘}).extract()if(soup.find(attrs={‘class‘:"col-xs-3"}) is notNone):

soup.find(attrs={‘class‘:"col-xs-3"}).extract()

with open(os.path.join(dirPath,fileName),"w+") as file:#pretify()方法返回一个美化过的html 字符串 encode(‘utf-8‘)指定编码--

file.write(soup.prettify(formatter=None).encode(‘utf-8‘))

最后

以上就是甜蜜服饰为你收集整理的python is beautiful_python BeautifulSoup基本用法的全部内容,希望文章能够帮你解决python is beautiful_python BeautifulSoup基本用法所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(34)

评论列表共有 0 条评论

立即
投稿
返回
顶部