Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8236595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:11:03+00:00 2026-06-07T19:11:03+00:00

I am trying to get href value from a html page NSURL *url =

  • 0

I am trying to get href value from a html page

NSURL *url = [[searchBar.text stringByReplacingOccurrencesofString:@" " withString:@"+"]];
NSString *html = [NSString stringWithContentOfURL:url encoding:NSASCIIStringEncoding error:&error
NSLog(@"Html = %@",html);

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.

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.

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

NSScanner *scanner = [NSScanner scannerWithString:self];
[scanner setCharactersToBeSkipped:nil];
NSMutableSet *tags = [[NSMutableSet alloc] init];
NSString *tag;
do {    
tag = nil;      
      [scanner scanUpToString:@"<" intoString:NULL];        
      [scanner scanUpToString:@">" intoString:&tag];        

      if (tag) {            
                 NSString *t = [[NSString alloc] initWithFormat:@"%@>", 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:@"<a>"] ||
        [t isEqualToString:@"</a>"] ||  
              [t isEqualToString:@"<span>"] ||
        [t isEqualToString:@"</span>"] ||
        [t isEqualToString:@"<strong>"] ||
        [t isEqualToString:@"</strong>"] ||
        [t isEqualToString:@"<em>"] ||  
              [t isEqualToString:@"</em>"]||
                          [t isEqualToString:@"<script>"]||
                          [t isEqualToString:@"</script>"])

                          { 
                              replacement = @"";    
                    }
[result replaceOccurrencesOfString:t withString:replacement options:NSLiteralSearch MakeRange(0, result.length)];   


     }


finalString = [result stringByRemovingNewLinesAndWhitespace];

Convert formatted HTML text string to NSString parts
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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:11:04+00:00Added an answer on June 7, 2026 at 7:11 pm

    Your best bet will be to modify the NSString+HTML category from your linked post. For example if you don’t want to remove the <a> tags, you could modify the code to something like this:

    Insert this to line 67 of the file linked above:

    if ([t isEqualToString:@"<a>"] || [t isEqualToString:@"</a>"]) continue;
    

    And remove the <a> conditions from the if following that line.

    Feel free to read, analyze and play with that code until you get what you need: all in all the best thing in open source world is that you can study everything what you don’t know from the already written code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get href value using jQuery: <html> <head> <title>Jquery Test</title> <script type=text/javascript
I'm trying to get the value of href from an anchor. The code looks
i cannot get current content page html. when i trying access from script in
I am trying to get an ID from a url parameter inside an href
I am trying to get the value of href of <a> that is the
I'm trying to get the first href attribute in a page using Selenium RC
I am trying to extract href and src links from an HTML string. According
I'm trying to return the track href value from the spotify api using the
Based on the thread With PHP preg_match_all, get value of href , I'm trying
How to download a file from a url with Javascript? I'm trying to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.