dtv55860 2012-05-19 01:47
浏览 63
已采纳

有谁知道在多个html文件中更换标签及其间的所有内容的最简单方法?

I have a lot of html files with custom style sheets within. I would like to create one universal style sheet that they all can use. So what i need to do is replace

< style type="text/css">

.Title {.... .body {..

< /style>

including the tags with this in multiple html files.

< link media="screen" href="style.css" type="text/css" rel="stylesheet" />

Im sure someone has ran into this problem and im wondering what would be the easiest way to accomplish this task? is there some kind of applescript or php script i can run to do this or is there another way of doing this?

  • 写回答

2条回答 默认 最新

  • douxing1850 2012-05-19 06:04
    关注

    I'd usually just use TextMate's Search in Project or some Ruby or shell script. I have a script like this saved as ggsub.rb and just modify it when I need to replace something in multiple files.

    #!/usr/bin/env ruby -Ku
    
    # paths = `find ~/Sites -name '*.html'`.chomp.split("
    ")
    paths = Dir["*.html"]
    
    paths.each do |path|
      html = File.read(path)
      html.sub!(/<style.*?>.*?<\/style>/m,
      "<link rel=\"stylesheet\" href=\"style.css\">")
      puts html
      # File.open(path, "w") { |f| f.puts(html) }
    end
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度