我正在尝试使用 HTMLParser解析此页面。使用列:“waluta”、“kupno”和“sprzedaż”。我的代码:
NSError * error = nil;
HTMLParser * parser = [[HTMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:@"https://www.deutsche-bank-pbc.pl/index.php/l1/kursy_walut"] error:&error];
if (error) {
NSLog(@"Error: %@", error);
parser = nil;
return;
}
NSLog(@"parser = %@", parser);
HTMLNode * bodyNode = [parser doc]; // получаем родительский элемент
HTMLNode *mynode = [bodyNode findChildWithAttribute:@"id" matchingName:@"container_c" allowPartial:NO]; // Берем div с id="all"
HTMLNode *mynode2 = [mynode findChildTag:@"table"];
NSArray *newsList = [mynode2 findChildrenOfClass:@"table_td_1"];
NSLog(@"newsList = %@",newsList];
for (HTMLNode *news in newsList) {
NSLog(@"element = %@",[news allContents] );
}
第一个 NSLog 显示了用 HTMLNode 对象填充的 NSArray。但是我循环中的 NSLog 显示了空元素:
2012-05-31 13:10:31.981 [11178:f803] element =
2012-05-31 13:10:31.982 [11178:f803] element =
2012-05-31 13:10:31.983 [11178:f803] element =
2012-05-31 13:10:31.983 [11178:f803] element =
我做错了什么?