1

I'm trying to build an iOS app like Pocket or Instapaper for practice. So, I need to fetch data from a url and strip the HTML of of it. I created the code below to do this.

NSURL *url = [NSURL URLWithString:self.link];
NSString *webData= [NSString stringWithContentsOfURL:url];

NSLog(@"webData is: %@", webData);

NSString *finalhtmlstring = [NSString stringWithFormat:@"%@", webData];
finalhtmlstring = [finalhtmlstring stringByConvertingHTMLToPlainText];

NSLog(@"FinalHTMLString is: %@", finalhtmlstring);

How would I fetch the body of the page? I can't get the NSString between @"<body>" and @"</body>", because some websites add attributes to the <body> tag.

user4486205
  • 105
  • 1
  • 7

1 Answers1

1

It sounds like parsing XML or HTML page.

Fortunately, there is open-source libraries likes Hpple can help you to get the contents from wrappers easily.

It wraps libxml2 nicely using Objective-C objects

Here is a tutorial about how to use this library.

Zigii Wong
  • 7,766
  • 8
  • 51
  • 79