#coding:utf-8
import os
from bs4 import BeautifulSoup
#jsp 路径
folderPath = "E:/whm/google/src_jsp" for dirPath,dirNames,fileNames in os.walk(folderPath):
for fileName in fileNames:
if fileName.endswith(".jsp"):
soup=BeautifulSoup(open(os.path.join(dirPath,fileName)),"html.parser")
if(soup.header is not None):
soup.header.extract()
#属性选择器。。。只能选择出第一个符合规则的元素
if(soup.find(attrs={'role':'banner'}) is not None):
soup.find(attrs={'role':'banner'}).extract()
if(soup.find(attrs={'class':"col-xs-3"}) is not None):
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'))

处理jsp页面会出现bug。。。 所以。。不要使用BeautifulSoup处理 jsp和php等脚本页面。。。需要用正则来写。。。这是我摸索半天得来的结论。。。。。

python BeautifulSoup基本用法的更多相关文章

  1. python BeautifulSoup库用法总结

    1. Beautiful Soup 简介 简单来说,Beautiful Soup是python的一个库,最主要的功能是从网页抓取数据.官方解释如下: Beautiful Soup提供一些简单的.pyt ...

  2. python beautifulsoup基本用法-文档搜索

    以如下html段落为例进行介绍 <html> <head> <title>The Dormouse's story</title> </head& ...

  3. python beautifulsoup基本用法-文档结构

    一.BeautifulSoup概述 BeautifulSoup是python的一个库,用于接收一个HTML或XML字符串并对其进行格式化,然后使用提供的方法快速查找指定元素. 使用BeautifulS ...

  4. 孤荷凌寒自学python第七十天学习并实践beautifulsoup对象用法3

    孤荷凌寒自学python第七十天学习并实践beautifulsoup对象用法3 (完整学习过程屏幕记录视频地址在文末) 今天继续学习beautifulsoup对象的属性与方法等内容. 一.今天进一步了 ...

  5. 孤荷凌寒自学python第六十九天学习并实践beautifulsoup对象用法2

    孤荷凌寒自学python第六十九天学习并实践beautifulsoup对象用法2 (完整学习过程屏幕记录视频地址在文末) 今天继续学习beautifulsoup对象的属性与方法等内容. 一.今天进一步 ...

  6. Python爬虫之BeautifulSoup的用法

    之前看静觅博客,关于BeautifulSoup的用法不太熟练,所以趁机在网上搜索相关的视频,其中一个讲的还是挺清楚的:python爬虫小白入门之BeautifulSoup库,有空做了一下笔记: 一.爬 ...

  7. python BeautifulSoup的简单使用

    官网:https://www.crummy.com/software/BeautifulSoup/bs4/doc/ 参考:https://www.cnblogs.com/yupeng/p/336203 ...

  8. python BeautifulSoup 介绍--安装

    Python中,专门用于HTML/XML解析的库: 特点是: 即使是有bug,有问题的html代码,也可以解析. BeautifulSoup主要有两个版本 BeautifulSoup 3 之前的,比较 ...

  9. python beautifulsoup/xpath/re详解

    自己在看python处理数据的方法,发现一篇介绍比较详细的文章 转自:http://blog.csdn.net/lingojames/article/details/72835972 20170531 ...

随机推荐

  1. python爬虫(7)--Beautiful Soup的用法

    1.Beautiful Soup简介 简单来说,Beautiful Soup是python的一个库,最主要的功能是从网页抓取数据. Beautiful Soup提供一些简单的.python式的函数用来 ...

  2. 使用/dev/dsp的wav文件播放器源码

    转载于:http://blog.csdn.net/dux003/article/details/5459423 #include #include #include #include #include ...

  3. css中的hack

    1.什么是CSS hack? CSS hack是通过在CSS样式中加入一些特殊的符号,让不同的浏览器识别不同的符号(什么样的浏览器识别什么样的符号是有标准的,CSS hack就是让你记住这个标准),以 ...

  4. 高性能MySQL笔记-第5章Indexing for High Performance-002Hash indexes

    一. 1.什么是hash index A hash index is built on a hash table and is useful only for exact lookups that u ...

  5. [译]javascript中的条件语句

    本文翻译youtube上的up主kudvenkat的javascript tutorial播放单 源地址在此: https://www.youtube.com/watch?v=PMsVM7rjupU& ...

  6. java反射机制的粗略理解

    java反射机制: 涉及的对象:Class, Object, 函数:Class类:[forName(String className):static:getClass():public],Object ...

  7. Arcgis android10.2测试版中android.view.InflateException

    最近2天总是有时出现  下面这个错误 android.view.InflateException: Binary XML file line #15: Error inflating class co ...

  8. C/C++使用心得:enum与int的相互转换

    如何正确理解enum类型? 例如: enum Color { red, white, blue}; Color x; 我们应说x是Color类型的,而不应将x理解成enumeration类型,更不应将 ...

  9. visual2013 的 MVC 4中连接数据库报错解决方案

    win7  64位安装vs2013后连接远程数据库出现下面的问题:A first chance exception of type 'System.AccessViolationException'  ...

  10. python3如何打印进度条

    Python3 中打印进度条(#)信息: 代码: import sys,time for i in range(50): sys.stdout.write("#") sys.std ...