国产探花免费观看_亚洲丰满少妇自慰呻吟_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
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 灵川县| 蛟河市| 门源| 新河县| 美姑县| 仁布县| 隆尧县| 辛集市| 遂溪县| 大田县| 文水县| 桂平市| 丰原市| 乌审旗| 乌拉特中旗| 修水县| 东丰县| 巴彦淖尔市| 阆中市| 榕江县| 乡城县| 英山县| 英超| 桦南县| 江华| 瑞昌市| 菏泽市| 木里| 井陉县| 武川县| 双江| 兰溪市| 桓台县| 云阳县| 阿瓦提县| 腾冲县| 井冈山市| 合阳县| 凤山市| 卢湾区| 资溪县|