The example in this article describes how Python clears script in all files in a specified directory. Share to everyone for your reference. Specific as follows:
Save the script as stripscripts.py
Call syntax: Python stripscripts.py
Usage Example: Python stripscripts.py d:\myfiles
# Hello, this was a script written in Python. See Http://www.pyhon.orgimport Os,sys,string,remessage = "" "Stripscripts 1.1p-script stripper This Script would walk a D Irectory (and its subdirectories) and disable all scripts (JavaScript, VBScript ...) from. html and. htm files. (The scripts is not being deleted, but simply deactivated, so that's can review them if you like.) Can be usefull for sites you has downloaded with httrack or similar tools. No more nosey or buggy scripts in your local HTML files. Syntax:python%s
Example:python%s D:\myfiles This script was public domain. You can freely reuse it. The author is Sebastien Sauvage
Http://sebsauvage.net more Quick & dirty scripts is available at http://sebsauvage.net/python/"" "% ((sys.argv[0 ],) 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 (directo Ry,filename)) def stripscriptfromhtml (filepath): print ' processing ', Os.path.split (filepath) [1] File = open (filepath , ' RB ') HTML = File.read () file.close () RegExp = Re.compile (R ')
', Re. IGNORECASE) HTML = regexp.sub ('