将其视为字符串,您可以使用 -
NSString *urlString = nil;
NSString *htmlString = //Your string;
NSScanner *scanner = [NSScanner scannerWithString:htmlString];
[scanner scanUpToString:@"href=" intoString:nil];
if (![scanner isAtEnd]) {
[scanner scanUpToString:@"http" intoString:nil];
NSCharacterSet *charset = [NSCharacterSet characterSetWithCharactersInString:@">"];
[scanner scanUpToCharactersFromSet:charset intoString:&urlString];
}
编辑 -
-(id) loadXMLByURL:(NSString *)urlString {
noticias = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
NSStringEncoding encoding;
NSString *xmlString = [NSString stringWithContentsOfURL:url usedEncoding:&encoding error:&error];
parser = [[NSXMLParser alloc] initWithData:[xmlString dataUsingEncoding:encoding allowLossyConversion:YES]];
parser.delegate = self;
[parser parse];
return self;
}