2
votes

How get src image and text (underline) from html string ?

src and style are fixed.

<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><div> src="http://and_Snorkel_Club.jpg" *style*="width: 300px; height: 225px; float: right; margin: 10px;" During spring break, the Mount Olive College SCUBA/Snorkel Club traveled to Crystal River, Florida to expand their knowledge on aquatic life and to obtain their Open Water certification.</div></div></div></div>

2
Are you getting this HTML from somewhere? Or is it guaranteed never to change?borrrden
I get this html from rss feed and Yes it's format not changed.src and style of text are fixed.user2129057

2 Answers

0
votes

If you want to get specific value from HTML content you need to Parse HTML content by using Hpple. Here's the documentation with exmple. (in this documentation you will find how to get src)

In your case you use: (by using Hpple)

TFHpple *dataParser = [TFHpple hppleWithHTMLData:placesData];

NSString *XpathQueryString = @"//div[@class='field-item even']/div/";
NSArray *listOfdata= [dataParser searchWithXPathQuery: XpathQueryString];

My code will be helpful for you.

0
votes
NSString *htmlString = @"<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><div> src="http://and_Snorkel_Club.jpg" *style*="width: 300px; height: 225px; float: right; margin: 10px;" During spring break, the Mount Olive College SCUBA/Snorkel Club traveled to Crystal River, Florida to expand their knowledge on aquatic life and to obtain their Open Water certification.</div></div></div></div>";

NSMutableString *imagLink = [[NSMutableString alloc] init];
NSScanner *scanner = [[NSScanner alloc] initWithString:htmlString];

[scanner scanUpToString:@"http://" intoString:nil];
[scanner scanUpToString:@""" *style" intoString:imgLink];

NSLog(@"%@", imgLink);

Similarly, you can apply this method to fetch other text of the HTML String. or Else you could use the way iPatel have shown.