ios获取html字符串中的title
2022-03-28 本文已影响0人
ONE2
NSError *error;
NSString *htmlStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"https://www.baidu.com"] encoding:NSUTF8StringEncoding error:&error];
if (!error && htmlStr.length) {
NSRange range = [htmlStr rangeOfString:@"(?<=title>).*(?=</title)" options:NSRegularExpressionSearch range:NSMakeRange(0, htmlStr.length - 1) locale:nil];
NSString *title = [htmlStr substringWithRange:range];
}