很高兴成为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
发布于 2017-11-07 02:23:27
可以通过几种方式使用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上:将双引号替换为单引号,反之亦然。
发布于 2020-10-30 09:52:29
您可以通过添加--output-format=xml选项来显示标记。
xidel --xquery '//div[@class="description"]' --output-format=xml file.html https://stackoverflow.com/questions/47139536
复制相似问题