Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-24-2009, 08:21 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Alaska
Posts: 63
Default Get NSString from text on HTML page?

Hi folks,

I'm working on an app that would require me to get some text from a webpage and copy it into a NSString. The text will always be enclosed in the same HTML tag on the site. Is what I want to do possible? Is so, could you possibly point me in the right direction?

Thanks in advance.

Merry Christmas!
mriphoneman is offline   Reply With Quote
Old 12-24-2009, 08:33 PM   #2 (permalink)
Registered Member
 
Swampmaster's Avatar
 
Join Date: Dec 2008
Posts: 26
Default

Couldn't be simpler, if I understood your question correctly:

NSString *string = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.apple.com/"]];
__________________
Number 14
NIM
Swampmaster is offline   Reply With Quote
Old 12-25-2009, 01:06 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Alaska
Posts: 63
Default

Quote:
Originally Posted by Swampmaster View Post
Couldn't be simpler, if I understood your question correctly:

NSString *string = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.apple.com/"]];
Awesome, I rigged that up to a textview and that worked great.

Do you possibly know how I would "find" that specific HTML tag in the NSString and then delete everything else?

Imagine a gas price app. The price of gas is embedded in someone's site, and I need to get just the gas price into my app, if that makes sense.

Thanks!
mriphoneman is offline   Reply With Quote
Old 12-26-2009, 10:48 AM   #4 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Atlanta
Posts: 411
Default

In my app using a UIWebView, I'm able to grab the page title: <title>Title Here</title> as Title Here using DOM.

DOM is used in PHP, Javascript, Java, many other languages; not to mention Objective-C.
Document Object Model - Wikipedia, the free encyclopedia

NSString *title = [webView stringByEvaluatingJavaScriptFromString:@"document. title"];
(please note the forum puts a space in document.title ...odd)
Take a look at the following link.

Note that this uses a UIWebview solution:
How To Inject JavaScript Functions Into a UIWebView | iPhone Development Blog

Last edited by funkytaco; 12-26-2009 at 10:56 AM.
funkytaco is offline   Reply With Quote
Old 12-26-2009, 12:47 PM   #5 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,578
Default

NSScanner is the easiest way to search for something in a string. I'm not at my computer, but if you look it up, you'll find code to search for a pattern, and record what comes after. So you could search for "gas price" and the store the actual price found.
JasonR is online now   Reply With Quote
Old 12-27-2009, 09:54 PM   #6 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Alaska
Posts: 63
Default Thanks.

Thanks for the help, everyone! I finally got it working!!!
mriphoneman is offline   Reply With Quote
Old 04-23-2010, 03:46 AM   #7 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 1
Default

Couldn't be simpler, if I understood your question correctly:
__________________
A lot of information here network+ certification and PMI-001 guide SY0-201 and VCP-410
jasonsmith092 is offline   Reply With Quote
Old 01-02-2011, 02:34 PM   #8 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 1
Default

Quote:
Originally Posted by Swampmaster View Post
Couldn't be simpler, if I understood your question correctly:

NSString *string = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.apple.com/"]];
Thanks Swampmaster.

Body fat time generally fat burning furnace used in combination with the diet solution. You could test eat stop eat because of tinnitus miracle nonetheless may not perform it's magic. seo link monster is exhilarating for link building services and consequently satellite direct has just a few top notch television programs.

Last edited by RobertSing; 12-31-2011 at 11:22 AM.
RobertSing is offline   Reply With Quote
Reply

Bookmarks

Tags
html, nsstring, uiwebview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 235
15 members and 220 guests
@sandris, ADY, Alsahir, dacapo, Dani77, djohnson, HemiMG, jansan, JasonR, MarkC, mer10, prchn4christ, ryandb2, tomtom100
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,882
Threads: 89,228
Posts: 380,762
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jansan
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:00 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0