【问题标题】:How to parse the content of the tag with attribute in iphone?如何在iphone中解析带有属性的标签内容?
【发布时间】:2011-01-24 23:21:58
【问题描述】:

我是 iphone 开发新手。我想从 url 的 HTML 文件中解析和检索特定内容。我有来自此链接的示例代码 http://blog.objectgraph.com/index.php/2010/02/24/parsing-html-iphone-development/

 NSData *htmlData = [[NSString stringWithContentsOfURL:[NSURL URLWithString: @"http://www.objectgraph.com/contact.html"]] dataUsingEncoding:NSUTF8StringEncoding];
 TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];  
 NSArray *elements  = [xpathParser search:@"//h3"]; // get the page title
 TFHppleElement *element = [elements objectAtIndex:0];
 NSString *h3Tag = [element content];  
 NSLog(h3Tag);
 mLabel.text = h3Tag;

他们正在检索源的 h3 标记中的内容,它正确显示联系我们。我已将 url 更改为堆栈溢出并搜索标题,它正确检索标题。但我无法检索内容标签的属性。请帮帮我。请指导我。谢谢

【问题讨论】:

    标签: iphone html-parsing libxml2


    【解决方案1】:

    您可以在查询中使用 //h3[@attribute='something']

    您可以使用 [元素属性] 来获取与该特定属性相关联的所有内容。

    【讨论】:

      猜你喜欢
      • 2011-10-23
      • 2012-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-04
      相关资源
      最近更新 更多