HTMLページを解析するためにtfhppleを使用しています。私はこの部分を解析しています:
<li>
<a title ="Return Kuban Krasnodar om 21.00 uur (87 reacties)" href="nieuws/23271-return-kuban-krasnodar-om-21-00-uur.html">
次のようなテーブルビューで表示しています:http://tinypic.com/r/4so5yp/5
href
しかし、ニュースアプリを作成しているため、そのURLを使用してそのページのテキストを詳細ビューに表示できるかどうか疑問に思っています。それは可能ですか?
これは、html を解析し、テーブルビュー内のすべてのタイトルを取得する方法です。また、詳細ビューに表示したいテキストを含む URL を含むすべての href を取得します。:
import "Fr12ListViewController.h"
import "Fr12Cell.h"
import "Fr12Opslag.h"
import "TFHpple.h"
import "Fr12DetailViewController.h"
@interface Fr12ListViewController ()
@end
@implementation Fr12ListViewController
@synthesize Fr12Content;
-(void)loadFr12Feed {
// 1
NSURL *Fr12WebsiteLink = [NSURL URLWithString:@"http://www.fr12.nl/"];
NSData *Fr12WebsiteHtmlData = [NSData dataWithContentsOfURL:Fr12WebsiteLink];
//
TFHpple *Fr12WebsiteParser = [TFHpple hppleWithHTMLData:Fr12WebsiteHtmlData];
// 3
NSString *Fr12WebsiteXpathQueryString = @"//div[@class ='content_left_extra']/ul/li/a";
NSArray *Fr12WebsiteNodes = [Fr12WebsiteParser searchWithXPathQuery:Fr12WebsiteXpathQueryString];
// 4
NSMutableArray *newFr12Website = [[NSMutableArray alloc] initWithCapacity:0];
for (TFHppleElement *element in Fr12WebsiteNodes) {
// 5
Fr12Opslag *fr12opslag = [[Fr12Opslag alloc] init];
[newFr12Website addObject:fr12opslag];
// 6
fr12opslag.title = [element objectForKey:@"title"];
// 7
bowtiefulimages.url = [element objectForKey:@"href"];
}
// 8
Fr12Content = newFr12Website;
[self.tableView reloadData];
}