2

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

谁能帮我?

4

1 回答 1

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”标签!而已!

于 2013-04-22T08:02:31.457 回答