#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int i, ic, j= 1;
do {
if (j>1)
[NSThread sleepForTimeInterval:30];
NSString *urlString= [NSString stringWithFormat:@"http://hoge.net/user/hoge?page=%d", j++];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [NSData dataWithContentsOfURL:url];
NSXMLDocument *document = [[[NSXMLDocument alloc] initWithData:data
options:NSXMLDocumentTidyHTML
error:NULL] autorelease];
NSError *error= nil;
NSArray *nodes = [document nodesForXPath:@"//div[@class='hoge']"
error:&error];
if (error!=nil) {
NSLog(@"%@", error);
break;
}
ic= [nodes count];
for(i= 0;i<ic;i++){
NSError *err= nil;
NSXMLElement *elem= [nodes objectAtIndex:i];
NSString *idString= [[elem attributeForName:@"id"] stringValue];
NSString *content= [elem XMLStringWithOptions:(NSXMLNodePrettyPrint|NSXMLNodeCompactEmptyElement)];
NSMutableString *outputString= [NSMutableString stringWithString:@"<html>"];
[outputString appendString:@"<head>"];
[outputString appendString:@"<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>"];
[outputString appendString:@"<base href='http://hoge.net/'>"];
[outputString appendString:@"</head>"];
[outputString appendFormat:@"<body>\n%@\n</body>", content];
[outputString appendString:@"</html>"];
[outputString writeToFile:[NSString stringWithFormat:@"/path/to/backup/%@.html", idString]
atomically:YES
encoding:NSUTF8StringEncoding
error:&err];
if (err!=nil) {
NSLog(@"%@", err);
break;
}
}
} while (ic>0);
[pool drain];
return 0;
}
0 件のコメント:
コメントを投稿