-(IBAction) grabWebPage{
//GBK编码。如果是UTF8,用NSUTF8StringEncoding
NSStringEncoding chineseEnc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSString *webString=[NSString stringWithContentsOfURL:[NSURL URLWithString:[textView text]] encoding:chineseEnc error:nil];
//设定起始标记
NSString *pageStart=@"<h1 class="\"fl\"" id="\"subject_tpc\"">";
NSString *pageEnd=@"<div id="\"w_tpc\"" class="\"c\"">";
int startOffset=[webString rangeOfString:pageStart].location;
int endOffset=[webString rangeOfString:pageEnd].location;
//截取substring
NSString *partialString=[webString substringWithRange:NSMakeRange(startOffset, endOffset-startOffset)];
//显示
[self.webView loadHTMLString:partialString baseURL:nil];
}
</div></h1>
ios 从网站抓取数据(转)
最新推荐文章于 2024-03-19 15:14:24 发布