有没有办法使用批处理文件查找和替换JavaScript代码。这是一个例子:
查找:<script type="text/javascript" src="http://www.mega.edu/Course/WebCTfooter/footer.js">Footer</script>
替换:<script type="text/javascript" src="http://www.mega.edu/Course/WebCTfooter/footer_ungrad.js">Footer</script>
非常感谢任何帮助。
答案 0 :(得分:0)
既然你可以使用python,我建议使用python程序而不是批处理文件,可能是这样的:
#!/usr/bin/python
import shutil
import sys
import re
for path in sys.argv[1:]:
print "processing " + path
infile = open(path,'r')
tmpfile = open(path+'.tmp','w')
# make the replacements
for line in infile:
line = re.sub("/footer.js","/footer_ungrad.js",line)
line = re.sub("/header.js","/header_ungrad.js",line)
line = re.sub("/sample.js","/sample_ungrad.js",line)
tmpfile.write(line)
infile.close()
tmpfile.close()
# now move it back to the original file
shutil.move(path+'.tmp',path)
使用python 2.4进行测试。