首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用批处理文件替换Javascript代码?

问使用批处理文件替换Javascript代码?
EN

Stack Overflow用户
提问于 2012-11-20 06:01:04
回答 1查看 355关注 0票数 0

有没有办法使用批处理文件查找和替换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>

任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-20 21:34:21

因为你可以使用python,所以我建议使用python程序而不是批处理文件,可能是这样的:

代码语言:javascript
复制
#!/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进行了测试。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13463056

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档