0

我正在htm使用 Web 视图在我的应用程序中显示文件,并且我希望能够对应用程序中的文件进行一些分析。例如,如果文件是 2009 年的足球赛程表,我想计算文件中“w”的数量,以便获得该赛季的总获胜次数。有任何想法吗?我的意思是“htm”文件。

4

2 回答 2

0

它可能对你有帮助

您可以从 webview 获取 html 字符串。

 NSString *currentURL = [theWebView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('title')[0].innerHTML;"];
于 2013-07-18T04:54:53.213 回答
0

您可以通过使用 NSScanner 类解析 html 来做到这一点

- (NSString *)flattenHTML:(NSString *)html {

    NSScanner *theScanner;
    NSString *text = nil;
    theScanner = [NSScanner scannerWithString:html];

    while ([theScanner isAtEnd] == NO) {

        [theScanner scanUpToString:@"<" intoString:NULL] ; 

        [theScanner scanUpToString:@">" intoString:&text] ;

        html = [html stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@>", text] withString:@""];
    }
    //
    html = [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    return html;
}
于 2013-07-18T04:55:58.607 回答