[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[其他] 请帮忙写个批处理,修改HTML文件内容自己写了几个老出现乱码。

<td width="212" align="left" nowrap class="style1">车牌号码</td>
<td width="212" align="left" nowrap class="style1">日期时间</td>
<td width="212" align="left" nowrap class="style1">1路温度</td>
<td width="212" align="left" nowrap class="style1">2路温度</td>
<td width="212" align="left" nowrap class="style1">3路温度</td>
<td width="214" align="left" nowrap class="style1">3路温度</td>
</tr>
<tr>
<td width="212" align="left" nowrap class="style5">14000544796</td>
<td width="212" align="left" nowrap class="style5">2014/11/17 13:00:13</td>
<td width="212" align="left" nowrap class="style5">-2.5</td>
<td width="212" align="left" nowrap class="style5">-2.5</td>
<td width="212" align="left" nowrap class="style5">未接</td>
<td width="214" align="left" nowrap class="style5">未接</td>

把14000544796,212 数值修改自己想要的
3路温度,3路温度,未接 整行删除 最后保存为html格式文件

找个html文件压缩之后传上来我试试

TOP

这个还是bat+vbs正则来弄吧。速度快些。

TOP

文件已上传,这个内容很少只是调整一下方便打印

TOP

我遇到过这个问题,你写的批处理可能没问题,关键问题可能是编码,批处理不可用处理utf-8编码的文件。现在的网站有很多是utf-8编码,可以修改成gbk就行了,文件少的话手动修改(用记事本打开另存为 编码:ANSI),或者使用第三方工具iconv进行转换

TOP

本帖最后由 amwfjhh 于 2014-11-26 12:36 编辑
  1. @if (0)==(0) echo off
  2. cscript -nologo -e:jscript %~s0 userinfo.sql utf-8 new.sql gb2312
  3. REM Do something here...
  4. pause
  5. goto :EOF
  6. @end
  7. //jscode
  8. var stream, strContent;
  9. var fileIn, fileOut;
  10. var inCode, outCode;
  11. if (WSH.arguments.length < 4) {
  12. WSH.ECHO("参数不完全……");
  13. WSH.ECHO("Usage: xxx fileIn inCode fileOut outCode");
  14. WSH.Quit();
  15. }
  16. fileIn = WSH.arguments(0);
  17. inCode = WSH.arguments(1);
  18. fileOut = WSH.arguments(2);
  19. outCode = WSH.arguments(3);
  20. if (fileIn == "" || inCode == "" || fileOut== "" || outCode == "") {
  21. WSH.ECHO("参数不完全……");
  22. WSH.ECHO("Usage: xxx fileIn inCode fileOut outCode");
  23. WSH.Quit();
  24. }
  25. stream = WSH.createobject("adodb.stream");
  26. stream.open();
  27. stream.charset = inCode;
  28. stream.LoadFromFile(fileIn);
  29. strContent = stream.ReadText();
  30. stream.Close();
  31. stream.Mode = 3;
  32. stream.Open();
  33. stream.Charset = outCode;
  34. stream.WriteText(strContent);
  35. stream.SaveToFile(fileOut, 2);
  36. stream.Close();
复制代码
先转成可识别的ANSI字符集,再进行处理。

TOP

回复 6# amwfjhh


    ADO 的话可以不转换ansi,直接改。
  1. @if (0)==(0) echo off
  2. set "htmlfile=LoginForm.html"
  3. set /p NewValue=输入新值:
  4. cscript -nologo -e:jscript "%~0" "%NewValue%" "%htmlfile%"
  5. pause
  6. goto :EOF
  7. @end
  8. arg = WScript.Arguments;
  9. with (new ActiveXObject("ADODB.Stream")){
  10.         Mode = 3;
  11.         Type = 2;
  12.         Charset = "utf-8";
  13.         Open();
  14.         LoadFromFile(arg(1));
  15.         s = ReadText(-1);
  16.         s = s.replace(/(<tr>[\s\S]+?")\d+"/ig, '$1' + arg(0) + '"');
  17.         s = s.replace(/.+>(未接|[34]路温度)<.*(\n|$)/g, '');
  18.         Position = 0;
  19.         WriteText(s);
  20.         SetEOS;
  21.         SaveToFile(arg(1), 2)
  22. }
复制代码

TOP

怎么唱的 码 看见问题多少时间完成的 晕

TOP

简单的文本也可以试试 powershell
  1. (type userinfo.sql) -notmatch '未接|[34]路温度'|out-file -encoding utf8 userinfo.sql
复制代码

TOP

回复 7# apang


    刚好手里面有一个类似的任务,需要转码为ANSI后,处理完毕在存为非ANSI字符集,就COPY下其中部分代码,如果简单任务确实直接JS里就处理完了。

TOP

回复 9# CrLf


    看 回车 兄的powershell用得炉火纯青真是羡慕啊。有没有系统学习的电子资料推荐一下啊(☆_☆)

TOP

回复 11# amwfjhh


只掌握了用过的知识,那些新概念的东西还是得随用随查...

个人感觉查手册或者 help pscommand -full 能解决很多问题,PowerShell2.0官方中文手册.chm 对一般用户而言是够用的了,再不行就上网查吧
不过现在 powershell 的网络资料还不是很全面,毕竟作为比较新的“非主流”脚本还缺少沉淀,经常要用其他语言的解决方案修改成 powershell 的
http://bbs.bathome.net/viewthread.php?tid=26220

想系统学习可以这里:
http://www.pstips.net/powershell-online-tutorials/
没事的时候逛逛某些大牛博客也常有斩获,除了 pstips,还有版主 victorwoo 的博客

TOP

powershell 是个强大的 shell,管理系统、处理简单事务的得力助手,可惜有默认安全限制,且 xp 虽退役却僵而不死,故不便作为脚本分发共享,蛋疼

TOP

一直用xp,虽然帮别人处理win7,win8问题都好多次了了,自己使用的还是xp,让你笑话了,我也是百度批处理问题到这里来之后才看到回复的多样命令中还有powershell这么一个东西,原想就看看就行了,公司最近整了一台server2008的机子,我看上面极力推荐使用powershell来替代cmd进行管理,有得折腾就有兴趣了……

TOP

回复 14# amwfjhh


系统管理方面 powershell 貌似无出其右,但其他一些方面和别的脚本或工具一比较总觉得有点杂而不精
反正说到底,我认识的 shell 就像坛徽上写的那样:化繁为简,提高工作效率
脚本这么多,各擅胜场,哪个合适用哪个啦,完全没有优势的东西早被淘汰了...

TOP

返回列表