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

首頁 > 編程 > Python > 正文

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

2019-11-02 14:31:07
字體:
來源:轉載
供稿:網友

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

  將腳本存儲為stripscripts.py

  調用語法 : python stripscripts.py

  使用范例 : python stripscripts.py d:myfiles

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 # 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>
快播電影網[www.aikan.tv/special/kuaibodianyingwang/]
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
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 定边县| 江川县| 桦南县| 高青县| 革吉县| 肥东县| 开鲁县| 怀来县| 彭山县| 尼玛县| 日土县| 政和县| 上高县| 平罗县| 汽车| 漳平市| 交口县| 福海县| 巴楚县| 龙岩市| 安西县| 滨州市| 阿拉善左旗| 靖江市| 夏河县| 霍邱县| 罗定市| 化州市| 昭苏县| 高邮市| 大宁县| 都江堰市| 石阡县| 仪陇县| 高雄县| 微山县| 林西县| 凤庆县| 故城县| 九台市| 明溪县|