【发布时间】: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