2012-11-09 1 views
0

Mon code:ne fonctionne pas stringByEvaluatingJavaScriptFromString objet c

[Web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:filePath]]]; 
    NSString *html = [Web stringByEvaluatingJavaScriptFromString: @"document.getElementsByClassName('bottomwideborder')[1].innerHTML;"]; 
    NSLog(@"%@", html); 

ne fonctionne pas avec ce fichier html - http://www.mosgortrans.org/pass3/shedule.php?type=avto&way=0&date=0000011&direction=AB&waypoint=1 (je tente d'extraire la table de html)

S'il vous plaît aidez-moi!

Répondre

0

Je suppose que vous utilisez Cocoa Touch (iOS), pour Cocoa (Mac OS X) c'est un peu différent. LoadRequest
démarre une requête client asynchrone.
Vous devez assigner un délégué à votre point de vue Web qui implémente le protocole UIWebViewDelegate et déplacez votre code dans la méthode webViewDidFinishLoading:

- (void)webViewDidFinishLoad:(UIWebView *)webView 
{ 
    NSString *html = [webView stringByEvaluatingJavaScriptFromString: @"document.body.getElementsByClassName('bottomwideborder')[1].innerHTML;"]; 
    NSLog(@"%@", html); 
} 
Questions connexes