我有下一个 html 结构
<div class="item column-1">
<h2>
<a href="/news/1172-zimnee-21-12-2014">
some text
</a>
</h2>
</div>
我想获取标签的内容,我正在使用此代码
NSURL *newURL = [NSURL URLWithString:@"http://mfc.mk.ua/news"];
NSData *newsData = [NSData dataWithContentsOfURL: newURL];
TFHpple *newsParser = [TFHpple hppleWithHTMLData: newsData];
NSString *newsXpathQueryString = @"//div[@class='item column-1']/h2/a";
NSArray *newsNodes = [newsParser searchWithXPathQuery: newsXpathQueryString];
NSMutableArray *newNews = [[NSMutableArray alloc] initWithCapacity: 0];
for (TFHppleElement *element in newsNodes)
{
News *news = [[News alloc] init];
[newNews addObject: news];
news.title = [[element firstChild] content];
_objects = newNews;
}
但它没有返回任何结果。如果我这样做:
news.title = [element objectForKey:@"href"];
然后我得到了结果。我做错了什么?请帮忙。