[英]extract table from index.html objective-c
問題如下:我正在嘗試使用“ stringByEvaluatingJavaScriptFromString”從html獲取表。 該表本身在NSLog中被拉出,但她不想出現在UIWebView中。 這是我的代碼:
- (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];
}
我認為應該以某種方式更新此頁面,但我不知道如何((
請幫助!
這可能是一個簡單的變量錯誤命名錯誤。
我懂了:
- (void)webViewDidFinishLoad:(UIWebView*)webView1
而您將該功能中的所有內容都稱為“ webView
”(不包含“ 1
”)。
另外,請確保您的“ webView
”不是NULL,並且正是您所期望的,因為您正嘗試使用(顯然正確解析的)“ html1
”代碼加載它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.