Created
August 13, 2013 13:21
-
-
Save taktamur/6220998 to your computer and use it in GitHub Desktop.
とあるページの要素分解 ref: http://qiita.com/paming/items/207641782b672222f401
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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