我使用@"document.getElementsByClassName('entry-content')[0].innerHTML";
提取html字符串,我成功获取html响应,其中我将其存储在一个字符串中,问题是我需要删除一个名为“collections-form”的div来自string的html响应。你们可以帮帮我。下面是代码。
-(void)webViewDidFinishLoad:(UIWebView *)webView1 {
NSLog(@"finish");
[activity hide:YES];
NSString *app;
if (currentPage == 3)
app=@"<style>table {font-size:10px;}</style>";
else app=@"<style>table {font-size:10px;}</style>";
NSString *temp1 = @"document.getElementsByClassName('entry-content')[0].innerHTML; " ;
NSString *class =[webView1 stringByEvaluatingJavaScriptFromString:temp1];
NSString *localString = [NSString stringWithFormat:@"%@%@",class,app];
[webView1 loadHTMLString:localString baseURL:nil];
webView.hidden = NO;
webView.delegate =nil;
}
答案 0 :(得分:0)
一个解决方案是调用js代码,在加载内容后删除该元素。
NSString *jsCommand = [NSString stringWithFormat:
@"var element = document.getElementById('%@'); element.parentElement.removeChild(element);",
@"id2",
];
[webView stringByEvaluatingJavaScriptFromString:jsCommand]
如果你想使用JavaScript,这是另一种方式
How to remove tag from html with JavaScript in iphone UIWebView