2016-06-17 8 views
0

Ich habe String von Webservice kommen und ich muss Wert von HTML-Tag holen.Wie kann ich Wert von HTML-Tag in IOS erhalten?

<b>Time:</b> Sunday, 17 July 2016 at 18:00<br /><b>Details:</b> Plug in to a regular feast of glorious gospel revelation!/Visit www.TheNewMystics.TV to become a premium member. Each month, John Crowder interacts live with viewers, answering questions, teaching and releasing the glory via live stream./Members can send in questions live, enjoy each month's broadcast and have access to all archive teachings.// Starts at 6 p.m. Pacific/ 9 p.m. Eastern<br /><b>Location:</b> www.thenewmystics.tv 

Wie kann ich Wert von Time, location und details von HTML String

Dank

+1

Haben Sie lesen diese document.https: //www.raywenderlich.com/14172/how-to-parse-html-on-ios –

+0

Es kann leicht durch die Verwendung erfolgen Der NSString-Teilstring funktioniert auch, wenn Sie die obige Lösung nicht verwenden möchten. – iphonic

Antwort

0

Sie substringWithRange verwenden können. Übergeben Sie HTML-Tags zwischen zwei Bereichen, zwischen denen Sie eine Zeichenfolge erhalten.

NSRange r1 = [s rangeOfString:@"<b>Time:</b>"]; 
NSRange r2 = [s rangeOfString:@"<br />"]; 
NSRange rSub = NSMakeRange(r1.location + r1.length, r2.location - r1.location - r1.length); 
NSString *sub = [s substringWithRange:rSub]; 
0

Sie könnten hpple verwenden!

wie:

#import "TFHpple.h" 

NSData * data  = [NSData dataWithContentsOfFile:@"index.html"]; 

TFHpple * doc  = [[TFHpple alloc] initWithHTMLData:data]; 
NSArray * elements = [doc search:@"//a[@class='sponsor']"]; 

TFHppleElement * element = [elements objectAtIndex:0]; 
[e text];      // The text inside the HTML element (the content of the first text node) 
[e tagName];     // "a" 
[e attributes];     // NSDictionary of href, class, id, etc. 
[e objectForKey:@"href"];  // Easy access to single attribute 
[e firstChildWithTagName:@"b"]; // The first "b" child node 
Verwandte Themen