国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python清除指定目錄內所有文件中script的方法

2019-11-25 17:14:53
字體:
來源:轉載
供稿:網友

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

將腳本存儲為stripscripts.py
調用語法 : python stripscripts.py <directory>
使用范例 : python stripscripts.py d:/myfiles

# Hello, this is a script written in Python. See http://www.pyhon.orgimport os,sys,string,remessage = """ 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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 盘锦市| 怀宁县| 崇文区| 南通市| 修文县| 麻城市| 时尚| 阿克陶县| 璧山县| 滦平县| 平和县| 宾川县| 海林市| 商河县| 永顺县| 三穗县| 北安市| 武强县| 彰化县| 荥阳市| 英德市| 北流市| 临沧市| 和静县| 阿克苏市| 大邑县| 鄂州市| 福鼎市| 新郑市| 冕宁县| 尼玛县| 榆树市| 运城市| 渭南市| 西安市| 桐梓县| 如东县| 双桥区| 册亨县| 曲沃县| 贵溪市|