【问题标题】:xidel template extract from button tag从按钮标签中提取的 xidel 模板
【发布时间】:2018-06-27 01:45:57
【问题描述】:
xidel https://www.url.com/folder -e "<button class="btn" type="BUTTON" onclick="self.location='https://www.url.com/folder/2'">Next &gt;</button>"

我正在尝试使用此 xidel 模板提取单引号之间的内容,但我无法快速完成。

<button class="btn" type="BUTTON" onclick="self.location='{.}'">Next &gt;</button>

我是否必须转义某些字符。语法令人困惑。我在 Windows 的命令行上使用它,最新版本。

【问题讨论】:

  • 如果您只想输出 url 的路径,那么 -e "$path" 就是您所需要的。
  • @Reino 语法如何查找?
  • 呃,就xidel https://www.url.com/folder -e "$path"

标签: templates xidel


【解决方案1】:

一开始我试过:

xidel -s https://www.fanfiction.net/s/12963528/1/Forced-Return -e "<button>{@onClick}</button>*"

但这给了我 5 个带有 onClick 属性的按钮结果,所以我需要更具体:

xidel -s https://www.fanfiction.net/s/12963528/1/Forced-Return -e "<div style='clear:both;text-align:right;'><button>{@onClick}</button></div>"

将输出:self.location='/s/12963528/2/Forced-Return'

所以,现在我们需要去掉前缀和单引号...... RegEx 很好:

xidel -s https://www.fanfiction.net/s/12963528/1/Forced-Return -e "<div style='clear:both;text-align:right;'><button>{extract(@onClick,'=.(.*).',1)}</button></div>"

这将输出你想要的:/s/12963528/2/Forced-Return

【讨论】:

  • 感谢您的帮助。我尝试执行上述操作,但它获取了整个 html 源代码。我只需要单引号内的 url
  • 如果可以,请发布您需要提取的真实 URL 和文本/属性...
  • xidel https://www.fanfiction.net/s/12963528/1/Forced-Return -e "&lt;button class="btn" type="BUTTON" onclick="self.location='/s/12963528/2/Forced-Return'"&gt;Next &amp;gt;&lt;/button&gt;" 我希望这是输出 /s/12963528/2/Forced-Return
  • 非常感谢您的帮助,因此 xpath 和 xquery 无法处理在没有正则表达式帮助的情况下正确转义的单引号或双引号。很高兴知道。
  • 在 xquery/xpath 中的引号可以用 "(double) 或 ' (单),但我已经在 xidel 行中使用了单引号和双引号,并且 xidel 解析似乎将它们替换回 ' 或 " 例如在 substring-before() 和 substring-after() 中,所以 RegEx 是对我来说最简单的方法...用户 BeniBela 或 Reino(Xidel 专家)可能知道如何以不同的方式逃避或规避这些引用。
猜你喜欢
  • 2014-08-04
  • 2018-04-18
  • 2017-02-16
  • 1970-01-01
  • 2022-07-22
  • 2016-10-06
  • 1970-01-01
  • 1970-01-01
  • 2021-02-12
相关资源
最近更新 更多