0
    -(NSMutableArray *)titlesFromString:(NSString *) pageData
{
    NSMutableArray *foundTitles=[[NSMutableArray alloc] init];
 NSScanner *scaningPage = [NSScanner scannerWithString:pageData];

    NSString *title;
    for (int i =0;i<4;i++) {
    [scaningPage scanUpToString:@"class='topic_title" intoString:NULL];
    [scaningPage scanUpToString:@">" intoString:NULL];
    scaningPage.scanLocation++;
    [scaningPage scanUpToString:@"</a></h4>" intoString:&title];
    [foundTitles addObject:title];
    }


   status.text = [[NSNumber numberWithInt:[foundTitles count]] stringValue];
    for (NSString *titlesLife in foundTitles){
        [results.text stringByAppendingString:@"\n"];
        [results.text stringByAppendingString:titlesLife];
    }
   return(nil);

}

right now i'm returning nil until get it working. I'm calling this method from connectionDidFinishLoading.

in the documentation they use a while loop while ([theScanner isAtEnd] == NO){} but they are also doing this on a regular data set, where the last thing scanned is at the end of the string so i'm guessing that's why i'm running into a bounds issue. i've also seen the RegexKit Framework and that may work better than the parser. until i get the while loop figured out i have a for loop just getting some of the info. I'm thinking i'll need to check for the existence of another element and if not then scan for in order to not have the scanner go out of bounds.

i'm also confused why i need to increment the scanner location once scanning the '>' into null other wise i end up with strings like "> What Song is On Right Now???" i'm also using a NSURLConnection to get the data when i think it may be simpler to use initWithContentsOfUrl but it's nice getting experience with the connection route.

the second chunk is me trying to add my results to the results UITextView which doesn't seem to be working. i shouldn't have to setNeedsDisplay should i? i thought that was only when drawing the view in code. Thanks for any suggestions.

mavriksc
  • 1,130
  • 1
  • 7
  • 10

1 Answers1

0

Part 2 first :

You're adding the extra text to your label's text and then throwing it away :)

Try something like this :

results.text = [results.text stringByAppendingString:@"\n"];

Part 1 is much tricker.

Dealing with HTML is a notoriously tricky problem :( However, there's a good answer to your problem here on stack overflow. I've never used that library but +61 votes is probably quite a good sign :)

Community
  • 1
  • 1
deanWombourne
  • 38,189
  • 13
  • 98
  • 110
  • ha. sweet thank you. i'll check out that other parser. but i think i figured it out. in the documentation it shows how you can use the return value of the of the parser method as a boolean showing it's existance if i use that as the condition in an if inside the while i think i can just say if ([parser findsSomething]){}else{ quit=true} and use quit as the condition to repeat. – mavriksc Jul 26 '12 at 21:44
  • looks like i can use nsregularexpressions instead and it's captures. seems like i'm getting an issue with bounds using the nsscanner to find content dynamically. – mavriksc Aug 22 '12 at 16:51