【问题标题】:Using wildcards for xpath query in the hpple library for iOS在 iOS 的 hpple 库中使用通配符进行 xpath 查询
【发布时间】:2014-06-04 23:29:09
【问题描述】:

我正在使用 hpple 库来解析 html 文档。该文档看起来像

<a class="title threadtitle_unread">Promo - 20 Apr 2014</a>
<a class="title">                   Promo - 19 Apr 2014</a>
<a class="title unread">            Promo - 18 Apr 2014</a>
<a class="title special">           Promo - 17 Apr 2014</a>
<a class="title threadtitle_unread">Promo - 16 Apr 2014</a>

我想使用 xpath 查询检索所有这些节点。所以,我尝试做类似的事情

TFHpple *parser = [TFHpple hppleWithHTMLData:htmlData];
NSString *xpathQueryString = @"//a[@class='title']";
NSArray *tutorialsNodes = [tutorialsParser searchWithXPathQuery:xpathQueryString];

但这可以理解地只返回一个节点,即

<a class="title">                   Promo - 19 Apr 2014</a>

我可以用通配符形成一个 xpath 搜索查询,让它返回所有这些节点吗?我试图将搜索查询形成为

NSString *xpathQueryString = @"//a[@class='title']"; 

但这没有帮助。

我可以使用 hpple 来实现吗?如果没有,我还有哪些其他选择?

谢谢

【问题讨论】:

    标签: html ios xpath html-parsing hpple


    【解决方案1】:

    另一种可能的方法是使用starts-with() 函数:

    //a[starts-with(@class,'title')]
    

    【讨论】:

    【解决方案2】:

    您应该使用contains 函数。例如

    //a[@class[contains(., 'title')]]
    

    【讨论】:

      猜你喜欢
      • 2012-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-21
      • 2010-09-18
      • 2023-01-10
      • 2017-03-19
      相关资源
      最近更新 更多