2013-03-04 77 views
2

只解析文本這是HTML:TFHpple前<br>標籤

<p id="content">Every Sunday, our Chef proposes a buffet high in color. 
<br> 
A brunch either classic or on a theme for special events 
<br> 
Every Sunday at the restaurant 
</p> 

這裏是我的代碼:

NSString *u = [[NSString alloc] initWithFormat:@"http//mydomain.com%@", _currentNews.url]; 
NSURL *url = [NSURL URLWithString:u]; 
NSData *paHtmlData = [NSData dataWithContentsOfURL:url]; 

TFHpple *paParser = [TFHpple hppleWithHTMLData:paHtmlData]; 

NSArray *array = [paParser searchWithXPathQuery:@"//p[@id='content']/text()"]; 
TFHppleElement *ele= [array objectAtIndex:0]; 

_currentBody.text = [ele text]; 
_currentTitle.text = _currentNews.title; 

我想分析<p id="content"></p>之間的所有文字,而不<br>

誰能幫我?

回答

0
NSString* webSIteSource=[NSString stringWithContentsOfURL:[NSURL URLWithString:u]encoding:NSUTF8StringEncoding error:nil]; 

    webSIteSource= [webSIteSource stringByReplacingOccurrencesOfString:@"<br />"withString:@" "]; 
    webSIteSource=[webSIteSource stringByReplacingOccurrencesOfString:@"<blockquote>" withString:@" "]; 
    webSIteSource=[webSIteSource stringByReplacingOccurrencesOfString:@"</blockquote>" withString:@" "]; 

只是將所有的網站內容添加到nsstring然後刪除所有「br」標籤! 就是這樣!