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

时间:2017-11-06 14:47:44

标签: html linux bash parsing xidel

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

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

我需要在

之间解析文本



<div class="description">
Text. <tag>Also tags.</tag> More text.
</div>
&#13;
&#13;
&#13;

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

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

得到我:

Text. Also tags. More text.

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

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

我怎样才能做到这一点?

问候,R

2 个答案:

答案 0 :(得分:1)

可以通过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上:将双引号换成单引号,反之亦然。

答案 1 :(得分:0)

您可以通过添加--output-format=xml选项来显示标签。

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