TFHpple仅在标签之前解析文本

时间:2013-03-04 18:46:17

标签: objective-c hpple

这是HTML:

<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>

的所有文字

任何人都可以帮助我吗?

2 个答案:

答案 0 :(得分: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”标签! 就是这样!

答案 1 :(得分:0)

_currentBody.text = ele.content

你可以尝试一下