Skip to content

Instantly share code, notes, and snippets.

@taktamur
Created August 13, 2013 13:21
Show Gist options
  • Save taktamur/6220998 to your computer and use it in GitHub Desktop.
Save taktamur/6220998 to your computer and use it in GitHub Desktop.
とあるページの要素分解 ref: http://qiita.com/paming/items/207641782b672222f401
NSString *html_ = [NSString stringWithContentsOfURL:url
encoding:NSUTF8StringEncoding
error:nil];
NSString *html = [html_ stringByReplacingOccurrencesOfString:@"\n"
withString:@""];
[UIApplication sharedApplication].networkActivityIndicatorVisible=NO;
// 正規表現の中で.*?とやると最短マッチするらしい。
NSRegularExpression *regexp = [NSRegularExpression regularExpressionWithPattern:@"<h5><a.*? href=\"(.*?)\".*?>(.*?)</a></h5>"
options:0
error:nil];
NSArray *arr = [regexp matchesInString:html
options:0
range:NSMakeRange(0, html.length)];
for (NSTextCheckingResult *match in arr) {
NSString *str1=[html substringWithRange:[match rangeAtIndex:2]];
NSString *str2=[html substringWithRange:[match rangeAtIndex:1]];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment