我要做的是解析网站上页面的多个部分。这是我正在做的事情:
NSURL *tutorialsUrl = [NSURL URLWithString:@"http://www.cetsp.com.br/"];
NSData *tutorialsHtmlData = [NSData dataWithContentsOfURL:tutorialsUrl];
TFHpple *tutorialsParser = [TFHpple hppleWithHTMLData:tutorialsHtmlData];
NSArray *holder;
NSString *tutorialsXpathQueryString = @"//div[@class='info oeste']/a/h4";
NSString *tutorialsXpathQueryString2 = @"//div[@class='info norte']/a/h4";
NSString *tutorialsXpathQueryString3 = @"//div[@class='info centro']/a/h4";
NSString *tutorialsXpathQueryString4 = @"//div[@class='info leste']/a/h4";
NSString *tutorialsXpathQueryString5 = @"//div[@class='info sul']/a/h4";
NSArray *oeste = [tutorialsParser searchWithXPathQuery:tutorialsXpathQueryString];
NSArray *norte = [tutorialsParser searchWithXPathQuery: tutorialsXpathQueryString2];
NSArray *centro = [tutorialsParser searchWithXPathQuery:tutorialsXpathQueryString3];
NSArray *leste = [tutorialsParser searchWithXPathQuery:tutorialsXpathQueryString4];
NSArray *sul = [tutorialsParser searchWithXPathQuery: tutorialsXpathQueryString5];
holder = [[NSArray alloc] initWithObjects:norte, oeste, centro,leste,sul, nil];
for (NSArray *array in holder) {
for (TFHppleElement *element in array) {
NSLog([[element firstChild] content]);
}
}
控制台记录了 5 个不同的正确结果,但正如您所见,我的代码非常乏味。那么如何获取多个标签的所有内容呢?
谢谢!