I am trying to get the image from this website, but I am having a hard time. All I need is the URL of the image, when I print the URL I get noting back. This is the URL and I am trying to get the main image seen in the middle, http://theoldrussuanbum.vsco.co/media/555722fde555153e3e8b4591
I have been trying the following code with no luck.
NSURL *URL = [NSURL URLWithString:_urlTextField.text];
NSURLSession *session = [NSURLSession sharedSession];
[[session dataTaskWithURL:URL completionHandler:
^(NSData *data, NSURLResponse *response, NSError *error) {
NSString *contentType = nil;
if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
NSDictionary *headers = [(NSHTTPURLResponse *)response allHeaderFields];
contentType = headers[@"Content-Type"];
}
HTMLDocument *document = [HTMLDocument documentWithData:data
contentTypeHeader:contentType];
HTMLElement *element = [document firstNodeMatchingSelector:@"img"];
NSString *urlString = element.attributes[@"src"];
NSLog(@"URL: %@", urlString);
}] resume];
Can anyone help?