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:@" "];

すべてのWebサイトコンテンツをnsstringに変換してから、すべての「br」タグを削除してください。それでおしまい!

于 2013-04-22T08:02:31.457 に答える