hpple从html解析表

时间:2012-11-09 17:40:46

标签: objective-c html-table html-parsing hpple

我遇到了“Hpple”的问题。我是解析html文件,我想得到整个表,但结果我得到(null)。

我在Objective-C中的代码:

-(void)loadTutorials {

    // 1

    paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    filePath = [NSString stringWithFormat:@"%@/%@", [paths objectAtIndex:0],@"index.html"];

    NSData  *data = [NSData dataWithContentsOfFile:filePath];

    // 2
    TFHpple * doc   = [[TFHpple alloc] initWithHTMLData:data];

    // 3
    NSString *tutorialsXpathQueryString = @"/html/body/div/table/tr/td[@class='bottomwideborder']"; //Next comes the big table

    NSArray *tutorialsNodes = [doc searchWithXPathQuery:tutorialsXpathQueryString];


    for (TFHppleElement *element in tutorialsNodes) {

        table = [element text];

    }

}

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self loadTutorials];

    html = [NSString stringWithFormat:@"<html><body>%@</body></html>", table];

    [Web loadHTMLString:html baseURL:nil];

}

我想要解析的表也很长,我觉得它对于NSString或NSArray来说太大了

我该怎么做才能解决这个问题?

0 个答案:

没有答案