0

I´m working on an app that displays 6 pictures from a website. These pictures change over time so I extracted the sourcecode of said website and managed to pull the first of the 6 pictures with this code:

NSError *error = nil;
NSString *deviantStringPopular;
deviantStringPopular = [NSString stringWithContentsOfURL:[NSURL     URLWithString:@"http://browse.deviantart.com/?order=24"]
                                         encoding:NSISOLatin1StringEncoding
                                            error:&error];
NSString *popularContent;
NSRange popularURLRange1 = [deviantStringPopular rangeOfString:@"super_img=\""];
NSRange popularURLRange2 = [deviantStringPopular rangeOfString:@"\" super_w"];
int lengt = popularURLRange2.location - popularURLRange1.location -     popularURLRange1.length;
int location = popularURLRange1.location + popularURLRange1.length;
NSRange endRange;
endRange.location = location;
endRange.length = lengt;
popularContent = [deviantStringPopular substringWithRange:endRange];
NSLog(@"%@", popularContent);

The problem is, the other 5 images' URLs are between the same substrings as the first one. So is it possible that the first image's URL is ignored once the it´s loaded successfully and the second one loads and is stored under a different variable and so on?

thanks in advance

2
  • please mention the relevant tags (such as cocoa) Commented Jul 1, 2011 at 14:24
  • Total side comment, but what is SO guidelines on discussions about copyrighted works? Commented Jul 1, 2011 at 15:19

2 Answers 2

0

To get 6 URLs from the string and load them into different variables, you could try using a loop. With each iteration, after the substring is found and stored into a variable, make a range from the beginning of the string up to the end of the substring you found. You can use stringByReplacingCharactersInRange to erase the part of the string already searched so that the next time you search the string for the substring, it will find the next URL.

Sign up to request clarification or add additional context in comments.

Comments

0

An easier solution may be to use RegexKit, if you know how to use RegEx's. Then each URL could just be a capture group.

1 Comment

Huh, haven´t heard of this yet, I´m pretty new to Objective C. Thanks for the advice, I´ll look into it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.