使用 Xidel
for /f "usebackqDELIMS=" %a in (`^"xidel -s file.html -e 'json(//script[@type="application/ld+json"])/(string)()'^"`) do set "string=%a"
在命令输出中运行时,会给出:
/(字符串()'“`)此时是意外的。
我想我需要转义一些字符,遵循以下文档 http://www.robvanderwoude.com/escapechars.php 我尝试了很多选择,对不同的字符使用胡萝卜,对[]使用反斜杠,但仍然会出现更多错误。
是否有某个字符需要转义或更多,或者根本不是这样?
我现在明白了 I wrongfully assumed you were on Linux Examples #9和10):
FOR /F "delims=" %%A IN ('xidel -s file.html -e "json(//script[@type='application/ld+json' ])/(string)()"') DO SET "string=%%A"
或
FOR /F "delims=" %%A IN ('xidel -s file.html -e "string:=json(//script[@type='application/ ld+json'])/(string)()" --output-format^=cmd') DO %%A