如何将html文档视为字符串

如何将html文档视为字符串,html,ios,uiwebview,Html,Ios,Uiwebview,我正在使用web视图在我的应用程序中显示htm文件,我希望能够对应用程序中的文件进行一些分析。例如,如果文件是2009年的足球赛程表,我想计算文件中“w”的数量,以获得该赛季的总胜利数。有什么想法吗? 我指的是“htm”文件。它可能对您有帮助 您可以从webview获取html字符串 NSString *currentURL = [theWebView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName(

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

它可能对您有帮助

您可以从webview获取html字符串

 NSString *currentURL = [theWebView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('title')[0].innerHTML;"];

您可以通过使用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;
}
-(NSString*)html:(NSString*)html{
NSScanner*扫描仪;
NSString*text=nil;
扫描仪=[NSScanner SCANNER WITHSTRING:html];
while([扫描仪显示]==否){
[扫描程序扫描字符串:@“intoString:&text];
html=[html stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@“%@>”,text]with string:@“”;
}
//
html=[html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
返回html;
}

你能给我解释一下这段代码吗?我对objective-c有点陌生