0

In My Application I need to Read HTML Page. For That Purapose I am removing the HTML tags Using the below code.

-(NSString *) stringByStrippingHTML:(NSString *)htmlStr
 {
    NSRange r;
    while ((r = [htmlStr rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound)
        htmlStr = [htmlStr stringByReplacingCharactersInRange:r withString:@""];
    htmlStr=[htmlStr stringByReplacingOccurrencesOfString:@"&nbsp;" withString:@"\n"];
    NSLog(@"html update is %@",htmlStr);
    return htmlStr; 
}

I am Getting result removing all tags its works Fine. But Now in My HTML page i need to read img Tag and their src element . Is there any way t read specic tag complete info. Please any one Help in this isse.

Thank In Advance.

4

2 回答 2

0

You can use

-(void)myMethod
{


NSString* htmlStr = @"<some>html</string>";
NSString* strWithoutFormatting = [self stringByStrippingHTML:htmlStr];

 }

-(NSString *)stringByStrippingHTML:(NSString*)str
 {
  NSRange r;
  while ((r = [str rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location     != NSNotFound)
  {
    str = [str stringByReplacingCharactersInRange:r withString:@""];
  }
  return str;
 }
于 2013-10-10T08:58:45.917 回答
0

链接将帮助检查以下方法

// 去除 HTML 标签和注释,去除多余的空格并解码 HTML 字符实体。
- (NSString *)stringByConvertingHTMLToPlainText;

// 使用 GTM 解码所有 HTML 实体。
- (NSString *)stringByDecodingHTMLEntities;

// 使用 GTM 编码所有 HTML 实体。
- (NSString *)stringByEncodingHTMLEntities;

// 最小的 unicode 编码只会覆盖表中的字符
- (NSString *)stringByEncodingHTMLEntities:(BOOL)isUnicode;

<br />// 用标签 替换换行符。
- (NSString *)stringWithNewLinesAsBRs;

// 从字符串中删除换行符和空格。
- (NSString *)stringByRemovingNewLinesAndWhitespace;

于 2012-12-06T06:25:08.417 回答