【问题标题】:not working stringByEvaluatingJavaScriptFromString object-c不工作 stringByEvaluatingJavaScriptFromString object-c
【发布时间】:2012-11-09 19:17:06
【问题描述】:

我的代码:

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

不适用于此 html 文件 - http://www.mosgortrans.org/pass3/shedule.php?type=avto&way=0&date=0000011&direction=AB&waypoint=1(我尝试从 html 中提取表格)

请帮帮我!

【问题讨论】:

    标签: html objective-c extract stringbyevaluatingjavascr


    【解决方案1】:

    我假设您使用的是 Cocoa Touch (iOS),对于 Cocoa (Mac OS X),它有点不同。
    loadRequest 启动异步客户端请求。
    您应该为实现 UIWebViewDelegate 协议的 Web 视图分配一个委托,并将您的代码移动到 webViewDidFinishLoading 方法中:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-10
      • 2014-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多