title: Retriving certain attributes from html with xcode
body: <p>I am trying to get href value from a html page</p>
  
  <pre><code>NSURL *url = [[searchBar.text stringByReplacingOccurrencesofString:@" " withString:@"+"]];
  NSString *html = [NSString stringWithContentOfURL:url encoding:NSASCIIStringEncoding error:&amp;error
  NSLog(@"Html = %@",html);
  </code></pre>
  
  <p>So far, up to this point of the code, it is working perfectly, in terms of getting the html from youtube and displaying the html for the first page of the search result.</p>
  
  <p>The next thing i tried to do is to remove some of the unwanted HTML tages that i do not need like ,,,, etc. All i want left would be the  and the  tags and their values or data with them.</p>
  
  <p>So i have tried using NSScanner and Regex.But i can't seem to get the desired result. The code that I am now trying is </p>
  
  <pre><code>NSScanner *scanner = [NSScanner scannerWithString:self];
  [scanner setCharactersToBeSkipped:nil];
  NSMutableSet *tags = [[NSMutableSet alloc] init];
  NSString *tag;
  do {    
  tag = nil;      
        [scanner scanUpToString:@"&lt;" intoString:NULL];        
        [scanner scanUpToString:@"&gt;" intoString:&amp;tag];        
  
        if (tag) {            
                   NSString *t = [[NSString alloc] initWithFormat:@"%@&gt;", tag];   
      [tags addObject:t];     
  
                 }    
     } while (![scanner isAtEnd]);    
  
  NSMutableString *result = [[NSMutableString alloc] initWithString:self];
  NSString *finalString;  
  NSString *replacement;  
   for (NSString *t in tags) {        
                 replacement = @" ";      
                        if ([t isEqualToString:@"&lt;a&gt;"] ||
          [t isEqualToString:@"&lt;/a&gt;"] ||  
                [t isEqualToString:@"&lt;span&gt;"] ||
          [t isEqualToString:@"&lt;/span&gt;"] ||
          [t isEqualToString:@"&lt;strong&gt;"] ||
          [t isEqualToString:@"&lt;/strong&gt;"] ||
          [t isEqualToString:@"&lt;em&gt;"] ||  
                [t isEqualToString:@"&lt;/em&gt;"]||
                            [t isEqualToString:@"&lt;script&gt;"]||
                            [t isEqualToString:@"&lt;/script&gt;"])
  
                            { 
                                replacement = @"";    
                      }
  [result replaceOccurrencesOfString:t withString:replacement options:NSLiteralSearch MakeRange(0, result.length)];   
  
  
       }
  
  
  finalString = [result stringByRemovingNewLinesAndWhitespace];
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/8148291/convert-formatted-html-text-string-to-nsstring-parts">Convert formatted HTML text string to NSString parts</a>
  This is where i refered from. But still i can't get it to work the way i need it to.I have been stuck for many days on the same problem, please help me.Any advice on how i should go about doing it would also help greatly.Thanks in advance.</p>