简体   繁体   English

从index.html Objective-c提取表

[英]extract table from index.html objective-c

the problem is the following: I'm trying to get a table from html using "stringByEvaluatingJavaScriptFromString". 问题如下:我正在尝试使用“ stringByEvaluatingJavaScriptFromString”从html获取表。 The table itself is pulled in NSLog, but she does not want to appear in the UIWebView. 该表本身在NSLog中被拉出,但她不想出现在UIWebView中。 Here is my code: 这是我的代码:

- (void)viewDidLoad
{
    [super viewDidLoad];

    paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    filePath = [NSString stringWithFormat:@"%@/%@", [paths objectAtIndex:0],@"index.html"];

    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:filePath]]];
}

- (void)webViewDidFinishLoad:(UIWebView*)webView1
{
    NSLog(@"webViewDidFinishLoad");

    html = [webView stringByEvaluatingJavaScriptFromString: @"document.body.getElementsByClassName('bottomwideborder')[1].innerHTML;"];
    html1 = [NSString stringWithFormat:@"<html><body>%@</body></html>", html];
    [webView loadHTMLString:html1 baseURL:[NSURL URLWithString:filePath]]; //Here page does not refresh

    NSLog(@"%@", html1); //It's all displayed

   [webView stopLoading];
}

I think this page should be updated somehow, but I do not know how (( 我认为应该以某种方式更新此页面,但我不知道如何((

Help please! 请帮助!

This might be a simple variable mis-naming error. 这可能是一个简单的变量错误命名错误。

I see: 我懂了:

- (void)webViewDidFinishLoad:(UIWebView*)webView1

while you're referring to everything within that function as " webView " (without the " 1 "). 而您将该功能中的所有内容都称为“ webView ”(不包含“ 1 ”)。

Also, make certain that your " webView " is not NULL and that it's what you're expecting it to be, since you're attempting to load it with the (apparently correctly parsed) " html1 " code. 另外,请确保您的“ webView ”不是NULL,并且正是您所期望的,因为您正尝试使用(显然正确解析的)“ html1 ”代码加载它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM