Xidel 提取标签内的数据 -- 原始输出



很高兴成为StackOverflow的成员,长期潜伏在这里。

我需要解析两个标签之间的文本,到目前为止,我找到了一个名为 Xidel 的精彩工具

我需要解析两者之间的文本

<div class="description">
Text. <tag>Also tags.</tag> More text.
</div>

但是,所述文本可以包含HTML标签,我希望它们以原始格式打印出来。因此,使用如下命令:

xidel --xquery '//div[@class="description"]' file.html

得到我:

Text. Also tags. More text.

我需要它完全原样,所以:

Text. <tag>Also tags.</tag> More text.

我怎样才能做到这一点?

问候,R

可以通过几种方式使用 Xidel 完成,这就是我如此喜欢它的原因。

HTML 模板化:

xidel -s file.html -e "<div class='description'>{inner-html()}</div>"

XPath:

xidel -s file.html -e "//div[@class='description']/inner-html()"

.CSS:

xidel -s file.html -e "inner-html(css('div.description'))"

顺便说一句,在 Linux 上:将双引号换成单引号,反之亦然。

您可以通过

添加--output-format=xml选项来显示标签。

xidel --xquery '//div[@class="description"]' --output-format=xml file.html 

最新更新