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

[文本处理] 批处理怎样提取代码中的图片链接,然后在链接两端加入内容?

原先在论坛里看到了,自己也改了下,但是达不到要的结果,请帮忙
要求:
1.提取daimai.txt中的链接,去掉spaceball.gif和space.gif结尾的链接
2.提取后在链接左侧加入<img align="absmiddle" src=",右侧加入" /></br>

谢谢!!!

结果连daimai.txt长什么样都没说

TOP

本帖最后由 lvlotus 于 2014-11-26 14:04 编辑

<p>
        <img alt="" src="http://img03.taobaocdn.com/imgextra/i3/1645847149/TB28owtXVXXXXXdXXXXXXXXXXXX-1645847149.jpg_.webp" style="margin: 0px; padding: 0px; border: 0px; vertical-align: middle; color: rgb(41, 83, 166); font-family: tahoma, arial, 微软雅黑, sans-serif; line-height: 16px;" /><br style="margin: 0px; padding: 0px; color: rgb(41, 83, 166); font-family: tahoma, arial, 微软雅黑, sans-serif; line-height: 16px;" />
        <img alt="" src="http://img01.taobaocdn.com/imgextra/i1/1645847149/TB2Qb.sXVXXXXcXXXXXXXXXXXXX-1645847149.jpg_.webp" style="margin: 0px; padding: 0px; border: 0px; vertical-align: middle; color: rgb(41, 83, 166); font-family: tahoma, arial, 微软雅黑, sans-serif; line-height: 16px;" /><br style="margin: 0px; padding: 0px; color: rgb(41, 83, 166); font-family: tahoma, arial, 微软雅黑, sans-serif; line-height: 16px;" />
        <img alt="" src="http://img04.taobaocdn.com/imgextra/i4/1645847149/TB2dd.sXVXXXXa6XXXXXXXXXXXX-1645847149.jpg_.webp" style="margin: 0px; padding: 0px; border: 0px; vertical-align: middle; color: rgb(41, 83, 166); font-family: tahoma, arial, 微软雅黑, sans-serif; line-height: 16px;" /><br style="margin: 0px; padding: 0px; color: rgb(41, 83, 166); font-family: tahoma, arial, 微软雅黑, sans-serif; line-height: 16px;" />
        <img alt="" src="http://img04.taobaocdn.com/imgextra/i4/1645847149/TB2wvMoXVXXXXbhXpXXXXXXXXXX-1645847149.jpg_.webp" style="margin: 0px; padding: 0px; border: 0px; vertical-align: middle; color: rgb(41, 83, 166); font-family: tahoma, arial, 微软雅黑, sans-serif; line-height: 16px;" />
<img src="http://img02.taobaocdn.com/imgextra/i2/1645847149/T2iSHvXGBXXXXXXXXX_%21%211645847149.jpg" width="456" />
<img src="http://img02.taobaocdn.com/imgextra/i2/1645847149/T2iSHvXGBXXXXXXXXX_%21%211645847149.png" width="456" />
<img src="http://img02.taobaocdn.com/imgextra/i2/1645847149/T2iSHvXGBXXXXXXXXX_%21%211645847149.jpg_.webp" width="456" />
<img src="http://img02.taobaocdn.com/imgextra/i2/1645847149/spaceball.gif" width="456" />
<img src="http://img02.taobaocdn.com/imgextra/i2/1645847149/space.gif" width="456" />
</p>

TOP

需要的结果是:

<img align="absmiddle" alt="alt" src="http://img02.taobaocdn.com/imgextra/i2/1645847149/T2d3fYXLtaXXXXXXXX_!!1645847149.jpg_.webp" />

TOP

_.webp这个无所谓,原本有就有,没有就没有

TOP

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. for /f "tokens=*" %%i in ('^<daimai.txt find /c /v "$"') do set /a lineCount=%%i
  4. <daimai.txt (
  5. for /l %%i in (1 1 !lineCount!) do (
  6. set /p line=
  7. ECHO !line:src=align^="absmiddle"^ src!
  8. )
  9. )
  10. pause
  11. goto :EOF
复制代码

TOP

  1. @if (0)==(0) echo off&setlocal enabledelayedexpansion
  2. for /f "delims=" %%i in ('^<daima.txt find /c /v ""') do set /a nLine=%%i
  3. <daima.txt >list.html (
  4. for /l %%i in (1,1,%nLine%) do (
  5. set /p strTmp=
  6. set strTmp=!strTmp:"='!
  7. for /f "tokens=*" %%a in ('echo "!strTmp!"^|findstr /i img ^>nul ^&^& cscript -nologo -e:jscript %~s0 "!strTmp!"^|findstr /iv spaceball') do (
  8. echo,^<img align="absmiddle" src="%%a" /^>^<br /^>
  9. )
  10. )
  11. )
  12. type list.html
  13. pause
  14. goto :EOF
  15. @end
  16. //jscode
  17. var str=WSH.arguments(0);
  18. var reg=/.*<img.*?src='([^']*)'.*>.*/g;
  19. var ret=reg.exec(str);
  20. if (reg != null) {
  21. WSH.echo(str.replace(reg, "$1"));
  22. }
复制代码

TOP

来一发:
  1. @echo off
  2. (for /f "delims=" %%a in ('findstr "src=" ttt.txt') do (
  3.    for %%b in (%%a) do (
  4.       if defined src set "src="&echo ^<img align="absmiddle" src="%%~b" /^>^</br^>
  5.       if /i %%b==src set "src=1"
  6.    )
  7. ))>tmp.txt
  8. findstr /ve "spaceball\.gif space\.gif" tmp.txt>结果.txt
  9. del tmp.txt
  10. pause
复制代码

TOP

本帖最后由 lvlotus 于 2014-11-27 23:06 编辑

还有些问题,能请教下吗

TOP

返回列表