12-24-2009, 08:21 PM
#1 (permalink )
Registered Member
Join Date: Nov 2009
Location: Alaska
Posts: 63
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!
12-24-2009, 08:33 PM
#2 (permalink )
Registered Member
Join Date: Dec 2008
Posts: 26
Couldn't be simpler, if I understood your question correctly:
NSString *string = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.apple.com/"]];
12-25-2009, 01:06 PM
#3 (permalink )
Registered Member
Join Date: Nov 2009
Location: Alaska
Posts: 63
Quote:
Originally Posted by
Swampmaster
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!
12-26-2009, 12:47 PM
#5 (permalink )
Super Moderator
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,578
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.
12-27-2009, 09:54 PM
#6 (permalink )
Registered Member
Join Date: Nov 2009
Location: Alaska
Posts: 63
Thanks.
Thanks for the help, everyone! I finally got it working!!!
04-23-2010, 03:46 AM
#7 (permalink )
Registered Member
Join Date: Apr 2010
Posts: 1
Couldn't be simpler, if I understood your question correctly:
01-02-2011, 02:34 PM
#8 (permalink )
Registered Member
Join Date: Jan 2011
Posts: 1
Quote:
Originally Posted by
Swampmaster
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 .
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» 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