0

如何修复此错误?

@echo off 
Setlocal EnableDelayedExpansion

REM LINES FOR TEST:
REM         <td><span><span>41</span><span style="display: none;">111</span><div
REM style="display: none;">190</div><span class="" style="">.</span><span>197</span><span
REM style="display: none;">24</span><span></span>.<span style="display: 
REM inline;">132</span><span style="display: none;">39</span>.<span 
REM style="display: inline;">186</span></span></td> 

SET line=inline;">132</span><span style="display: none;">39</span>.<span 

FOR /F "tokens=1-20 delims=<>" %%A IN (%line%) DO (
echo A:%%A + B:%%B + C:%%C + D:%%D + E:%%E + F:%%F + G:%%G + H:%%H + I:%%I + J:%%J + K:%%K + L:%%L
FOR %%? in ( "%%A", "%%B", "%%C", "%%D", "%%E", "%%F", "%%G", "%%H", "%%I", "%%J") DO (
SET $=%%?
echo $:!$!
)
pause
)

我想用标签分隔行。但我得到了错误:> 不是预期的

编辑:

I tried this:
SET line=inline;">132</span><span style="display: none;">39</span>.<span 
FOR /F usebackq^ tokens^=1-20^ delims^=^>^< %%A IN (^"%line%^") DO (
echo A:%%A + B:%%B + C:%%C + D:%%D + E:%%E + F:%%F + G:%%G + H:%%H + I:%%I + J:%%J + K:%%K + L:%%L
FOR %%? in ( "%%A", "%%B", "%%C", "%%D", "%%E", "%%F", "%%G", "%%H", "%%I", "%%J") DO (
SET $=%%?
echo $:!$!
)
pause
)

错误:系统找不到内联文件 ">132

另一个测试- 我将这些行移到文件中并且没有错误

FOR /F "delims= " %%? IN (html_2.txt) DO ( echo %%? FOR /F "tokens=1-20 delims=><" %%A IN ("%%?") DO ( echo A:%%A + B:%%B + C:%%C + D:%%D + E:%%E + F:%%F + G:%%G + H:%%H + I:%%I + J:%%J + K:%%K + L:%%L FOR %%? in ( "%%A", "%%B", "%%C", "%%D", "%%E", "%%F", "%%G", "%%H", "%%I", "%%J") DO ( SET $=%%~? echo $:!$! ) pause ) )

4

4 回答 4

1

<并且>是重定向运算符,您需要转义它们:^>

于 2012-06-21T16:27:10.570 回答
1

试试这个:

FOR /F "tokens=1 delims=" %%A IN (html_2.txt) DO (
    set a=%%A 
    set a=!a:"=\q!
    echo a=!a!
    FOR /F "tokens=1-26 delims=<>" %%a in ( "!a!" ) DO ( 
        set a=%%a& echo $:!a:\q="!
        set b=%%b& echo $:!b:\q="!
        set c=%%c& echo $:!c:\q="!
        set d=%%d& echo $:!d:\q="!
        set e=%%e& echo $:!e:\q="!
        set f=%%f& echo $:!f:\q="!
        set g=%%g& echo $:!g:\q="!
        set h=%%h& echo $:!h:\q="!
        rem repeat thru to z
        )
    pause
    )
于 2012-06-21T21:01:34.207 回答
0

这是 Skip R 代码的缩短版本:

@echo off 
Setlocal EnableDelayedExpansion

FOR /F "tokens=1 delims=" %%A IN (html_2.txt) DO (
    set a=%%A 
    set a=!a:"=\q!
    echo a=!a!
    FOR /F "tokens=1-26 delims=<>" %%A in ( "!a!" ) DO ( 
        FOR %%Z in ( %%A, %%B, %%C, %%D, %%E, %%F, %%G, %%H, %%I, %%J) DO (
        set z=%%Z
        echo !z:\q="!
        )
    )
    pause
)
于 2012-06-22T07:09:12.697 回答
0

问题不在您的FOR/F循环中。这是您的变量lineFOR/F ... in (^"%line%^").
在此处使用延迟扩展或更好地从文件中读取内容。

这可以在不考虑感叹号或插入符号的情况下处理您的问题。

@echo off 
setlocal EnableDelayedExpansion

FOR /F "tokens=1-26 delims=<>" %%A IN (html_2.txt) DO (
   echo a=%%A
   echo b=%%B
   echo c=%%C
   echo d=%%D
   echo e=%%E
   rem ...
   echo z=%%Z
)

通过保留感叹号和插入符号,您需要切换延迟扩展模式并将值保存在临时变量中。
要禁用 EOL 字符,我将其设置为分隔符之外的字符。

@echo off 
setlocal DisableDelayedExpansion

FOR /F "tokens=1-26 EOL=< delims=<>" %%A IN (html_2.txt) DO (
    set "paramA=%%A"
    set "paramB=%%B"
    set "paramC=%%C"
    rem ...
    set "paramZ=%%Z"

   setlocal EnableDelayedExpansion
   echo a=!paramA!
   echo b=!paramB!
   echo c=!paramC!
   rem ...
   echo z=!paramZ!
   endlocal
)

用 html_2.txt 测试:

<td><span><span>41</span><span style="display: none;">111</span><div
style="display: none;">190</div><span class="" style="">.</span><span>197</span><span
style="display: none;">24</span><span></span>.<span style="display: 
inline;">132</span><span style="display: none;">39</span>.<span 
style="display: inline;">186</span></span></td>
于 2012-06-26T07:43:22.333 回答