Teach to use the parser. Everyone knows the site yandex.ru . I was able to write a program that takes the source code of this site. I can not write a parser that takes weather from this site. Straight from the main page. I need only three characters, for example: +25. All source code is written to the variable NSString *str
.
PS: Anyone can see the source code of the main page of Yandex. So, it is written in the string variable str
. Here I need to unzip it and get only characters with weather into another string variable. The parser code is the source code for Yandex. But a little necessary code
NSError * error = nil; HTMLParser * parser = [[HTMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.yandex.ru"] error:&error]; if (error) { NSLog(@"Error: %@", error); [parser release]; parser = nil; return; } HTMLNode * bodyNode = [parser doc]; // получаем родительский элемент HTMLNode *mynode = [bodyNode findChildWithAttribute:@"id" matchingName:@"all" allowPartial:TRUE]; // Берем div с id="all" NSArray *newsList = [mynode findChildTags:@"li"]; // получаем NSArray HTMLNode элеметнов содержащих li тэги с новостями на главной for (HTMLNode *news in newsList) { // Пробегаем по списку тэгов и выводим новости NSLog(@"Новость: %@", [news allContents]); // выводим текст из HTMLNode news и всех children } [parser release]; // освобождаем память