【问题标题】:How to exclude class from Xidel output如何从 Xidel 输出中排除类
【发布时间】:2016-04-28 20:59:13
【问题描述】:

我想使用 xpath 优化我的 Xidel 输出://BODY/DIV 删除包含“AClass”的行,并仅保留包含“MyClass”的行

我可以在 Xidel 输出文件中添加换行符吗?

<a class="AClass" href="http://www.mywebsite.com/file1" target="_blank"> File1 </a>    
<a class="AClass" href="http://www.mywebsite.com/file2" target="_blank"> File2 </a>    
<a class="AClass" href="http://www.mywebsite.com/file3" target="_blank"> File3 </a>
<a class="AClass" href="http://www.mywebsite.com/file4" target="_blank"> File4 </a>
<a class="MyClass" href="http://www.mywebsite.com/file5" target="_blank"> File5 </a>
<a class="AClass" href="http://www.mywebsite.com/file6" target="_blank"> File6 </a>
<a class="MyClass" href="http://www.mywebsite.com/file7" target="_blank"> File7 </a>

【问题讨论】:

  • 您使用的是哪个 XPath 表达式? //body/div 将返回 divs 的列表,而不是 as。通常可以使用[]except 进行过滤

标签: html web-scraping xidel


【解决方案1】:

要使用 XQuery 排除属性,我们可以使用正则不等式,在您的示例中为 //a[@class !="AClass"]

这匹配所有&lt;a&gt;,无论深度如何,包含属性类其中不等于AClass

至于您的另一个问题,关于在 xidel 的输出文件中添加换行符,确实可以使用 --output-footer--output-separator 标志,具体取决于您的意思。

--output-footer 将一个字符串附加到所有输出的末尾(例如多个换行符)。

--output-separator 在每个项目的末尾附加一个字符串。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-22
    • 1970-01-01
    • 1970-01-01
    • 2021-02-02
    • 2011-02-23
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多