문제

My code:

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

Not working for this html file - http://www.mosgortrans.org/pass3/shedule.php?type=avto&way=0&date=0000011&direction=AB&waypoint=1 (I try to extract table from html)

Please help me!

도움이 되었습니까?

해결책

I'm supposing you are using Cocoa Touch (iOS), for Cocoa (Mac OS X) it's a bit different.
loadRequest starts an asynchronous client request.
You should assign a delegate to your web view that implements UIWebViewDelegate protocol and move your code into the webViewDidFinishLoading method:

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSString *html = [webView stringByEvaluatingJavaScriptFromString: @"document.body.getElementsByClassName('bottomwideborder')[1].innerHTML;"];
    NSLog(@"%@", html);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top