【问题标题】:What characters to escape on cmd to work with Xidel scripting在 cmd 上转义哪些字符以使用 Xidel 脚本
【发布时间】:2018-08-19 21:59:51
【问题描述】:

使用Xidel 抓取 HTML:

for /f "usebackqDELIMS=" %a in (`^"xidel -s file.html -e 'json(//script[@type="application/ld+json"])/(string)()'^"`) do set "string=%a"

在 CMD 中运行时输出:

/(string)()'"`) 这个时候出乎意料。

我假设我需要转义一些字符,遵循此文档 http://www.robvanderwoude.com/escapechars.php 我尝试了很多选项,对各种字符使用胡萝卜,对 [] 使用反斜杠,但不断收到更多错误。

是否有某个字符需要转义或更多,或者根本不是这种情况?

【问题讨论】:

  • 如果您尝试在批处理脚本中使用它,您的第一个问题是您需要将%a 更改为%%a。其次,(`` & ``)需要改为('&')

标签: cmd xidel


【解决方案1】:

我现在看到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

让 Xidel 为您分配变量。

【讨论】:

  • 知道为什么它将垃圾邮件发送出去会导致单独的字符串,而不是全部在一个字符串中吗?现在它为每行设置一个新字符串,因此技术上只保存最后一个字符串。
  • 我假设您指的是 Github 问题。那么您可能忘记将流派项目进行字符串连接:... -e "string:=json(//script[@type='application/ld+json'])/join((genre)(),', ')" ...。顺便说一句,如果你对这个答案感到满意,你能竖起大拇指吗? (并以同样的方式关闭 Github-issue)
  • 它适用于 cmd,但是当我将它包含在最终批处理脚本中时,它会给出 the filename directory name or volume label syntax is incorrect 错误。
猜你喜欢
  • 2021-09-09
  • 1970-01-01
  • 2011-07-23
  • 2013-03-24
  • 2021-06-20
  • 2014-05-14
  • 1970-01-01
  • 1970-01-01
  • 2019-02-24
相关资源
最近更新 更多