欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python清除指定目錄內(nèi)所有文件中script的方法

 更新時間:2015年06月30日 14:39:38   作者:秋風秋雨  
這篇文章主要介紹了python清除指定目錄內(nèi)所有文件中script的方法,涉及Python針對文件、字符串及正則匹配操作的相關(guān)技巧,需要的朋友可以參考下

本文實例講述了python清除指定目錄內(nèi)所有文件中script的方法。分享給大家供大家參考。具體如下:

將腳本存儲為stripscripts.py
調(diào)用語法 : python stripscripts.py <directory>
使用范例 : python stripscripts.py d:\myfiles

# Hello, this is a script written in Python. See http://www.pyhon.org
import os,sys,string,re
message = """
 stripscripts 1.1p - Script stripper
 This script will walk a directory (and its subdirectories) and disable
 all scripts (javascript, vbscript...) from .html and .htm files.
 (The scripts will not be deleted, but simply deactivated, so that
 you can review them if you like.)
 Can be usefull for sites you have downloaded with HTTrack or similar tools.
 No more nosey or buggy scripts in your local html files.
 Syntax : python %s <directory>
 Example : python %s d:\myfiles
 This script is public domain. You can freely reuse it.
 The author is
    Sebastien SAUVAGE
    <sebsauvage at sebsauvage dot net>
    http://sebsauvage.net
 More quick & dirty scripts are available at http://sebsauvage.net/python/
""" % ((sys.argv[0], )*2)
def stripscripts ( directoryStart ) :
  os.path.walk( directoryStart, callback, '' )
def callback ( args, directory, files ) :
  print 'Scanning',directory
  for fileName in files:
    if os.path.isfile( os.path.join(directory,fileName) ) :
      if string.lower(os.path.splitext(fileName)[1]) in ['.html','.htm'] :
        stripScriptFromHtml ( os.path.join(directory,fileName) )
def stripScriptFromHtml ( filepath ) :
  print ' Processing',os.path.split(filepath)[1]
  file = open(filepath, 'rb')
  html = file.read()
  file.close()
  regexp = re.compile(r'<script.*?>', re.IGNORECASE)
  html = regexp.sub('<script language="MonthyPythonsScript">',html)
  file = open(filepath, 'w+')
  file.write(html)
  file.close()
if len(sys.argv) > 1 :
  stripscripts( sys.argv[1] )
else:
  print message

希望本文所述對大家的Python程序設計有所幫助。

相關(guān)文章

  • python Matplotlib基礎--如何添加文本和標注

    python Matplotlib基礎--如何添加文本和標注

    這篇文章主要介紹了python Matplotlib基礎--如何添加文本和標注,幫助大家更好的利用Matplotlib繪制圖表,感興趣的朋友可以了解下
    2021-01-01
  • 使用pip安裝python庫的多種方式

    使用pip安裝python庫的多種方式

    這篇文章主要介紹了使用pip安裝python庫的幾種方式,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-07-07
  • 3分鐘學會一個Python小技巧

    3分鐘學會一個Python小技巧

    Python時間日期轉(zhuǎn)換在開發(fā)中是非常高頻的一個操作,你經(jīng)常會遇到需要將字符串轉(zhuǎn)換成 datetime 或者是反過來將 datetime 轉(zhuǎn)換成字符串,今天小編給大家?guī)砹艘粋€Python小技巧,感興趣的朋友一起看看吧
    2018-11-11
  • python中使用paramiko模塊并實現(xiàn)遠程連接服務器執(zhí)行上傳下載功能

    python中使用paramiko模塊并實現(xiàn)遠程連接服務器執(zhí)行上傳下載功能

    paramiko是用python語言寫的一個模塊,遵循SSH2協(xié)議,支持以加密和認證的方式,進行遠程服務器的連接。這篇文章主要介紹了python中使用paramiko模塊并實現(xiàn)遠程連接服務器執(zhí)行上傳下載功能,需要的朋友可以參考下
    2020-02-02
  • python批量修改xml文件中的信息

    python批量修改xml文件中的信息

    大家好,本篇文章主要講的是python批量修改xml文件中的信息,感興趣的同學趕快來看一看吧,對你有幫助的話記得收藏一下的相關(guān)資料
    2022-01-01
  • 用Python的SimPy庫簡化復雜的編程模型的介紹

    用Python的SimPy庫簡化復雜的編程模型的介紹

    這篇文章主要介紹了用Python的SimPy庫簡化復雜的編程模型的介紹,本文來自于官方的開發(fā)者技術(shù)文檔,需要的朋友可以參考下
    2015-04-04
  • 在Python中處理字符串之isdecimal()方法的使用

    在Python中處理字符串之isdecimal()方法的使用

    這篇文章主要介紹了在Python中處理字符串之isdecimal()方法的使用,是Python入門學習的基礎知識,需要的朋友可以參考下
    2015-05-05
  • 跟老齊學Python之Python安裝

    跟老齊學Python之Python安裝

    本文主要講訴了在Linux,Windows,MacOS三大系統(tǒng)中如何安裝Python環(huán)境,非常的實用,雖然前面絮絮叨叨的說了不少題外話,但都是作者的肺腑之言,還是仔細看看吧
    2014-09-09
  • Python3標準庫之functools管理函數(shù)的工具詳解

    Python3標準庫之functools管理函數(shù)的工具詳解

    functools模塊提供的主要工具就是partial類,可以用來“包裝”一個有默認參數(shù)的callable對象。這篇文章主要介紹了Python3標準庫functools管理函數(shù)的工具的實例詳解,需要的朋友可以參考下
    2020-02-02
  • python?實時獲取kafka消費隊列信息示例詳解

    python?實時獲取kafka消費隊列信息示例詳解

    這篇文章主要介紹了python實時獲取kafka消費隊列信息,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-07-07

最新評論