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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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 10-23-2008, 12:08 AM   #1 (permalink)
Registered Member
 
Marco's Avatar
 
Join Date: Apr 2008
Posts: 69
Marco is an unknown quantity at this point
Default UIWebView - How to get the content that is shown

Is there a way to get the content (the text inside the UIWebView) of the UIWebView?

I tried [[webView request] HTTPBodyStream]; but I was getting a crash.
__________________
Peace in Christ
Marco Napoli
http://www.ourlovingmother.org
Marco is offline   Reply With Quote
Old 10-23-2008, 01:51 PM   #2 (permalink)
Registered Member
 
Marco's Avatar
 
Join Date: Apr 2008
Posts: 69
Marco is an unknown quantity at this point
Default

I found the solutions and I will post it just in case it might help someone else.

Code:
NSString *myText = [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.textContent"];
__________________
Peace in Christ
Marco Napoli
http://www.ourlovingmother.org

Last edited by Marco; 10-23-2008 at 01:51 PM. Reason: had the wrong name for webView
Marco is offline   Reply With Quote
Old 03-27-2009, 04:42 PM   #3 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: Oceanside, CA
Posts: 570
aryaxt is on a distinguished road
Default

that doesn't seem to return the html code
it only return the text inside the uiwebView
is there any way to get the full html?
for example i add
<font color="red">qasdasd</font>
when i try to read the content i get "qasdasd"
aryaxt is offline   Reply With Quote
Old 03-27-2009, 11:20 PM   #4 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 4
DC Studios is on a distinguished road
Default

Quote:
Originally Posted by aryaxt View Post
that doesn't seem to return the html code
it only return the text inside the uiwebView
is there any way to get the full html?
for example i add
<font color="red">qasdasd</font>
when i try to read the content i get "qasdasd"
That's because in the example he grabs everything the textContent property contains. You can use the body's inner HTML to get the tags. Just change the JavaScript to
Code:
document.body.innerHTML
DC Studios is offline   Reply With Quote
Old 03-28-2009, 12:06 AM   #5 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: Oceanside, CA
Posts: 570
aryaxt is on a distinguished road
Default

thanks
I used "document.documentElement.outerHTML"
that worked for me 2
aryaxt is offline   Reply With Quote
Old 04-01-2009, 01:32 AM   #6 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,971
Bertrand21 is on a distinguished road
Default

do you know how to use this to get the title of the page presented? i tried
@"document.title.textContent" but did not bring back anything

****SOLVED 2 minutes later**** with
"document.title"
__________________
Haters gonna Hate
Likers gonna Like

Last edited by Bertrand21; 04-01-2009 at 01:35 AM.
Bertrand21 is offline   Reply With Quote
Old 04-23-2009, 02:22 AM   #7 (permalink)
New Member
 
Join Date: Feb 2009
Location: Bangkok
Posts: 145
DGYWFT is on a distinguished road
Default

I did not know you could pull data from the UIWebView like this, this is great! So if I wanted to send some text to the application, I could put the text in a div with an id/name, hide the div so its not shown, then extract it like above to be used somewhere in my apps view?
DGYWFT is offline   Reply With Quote
Old 07-28-2009, 05:40 PM   #8 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 19
farhadf is on a distinguished road
Default

The API seems really weak here. Is it just me or does this seem like a really roundabout way of getting at the content? A "content" or "text" property would seem more appropriate.
farhadf is offline   Reply With Quote
Old 11-29-2009, 09:51 PM   #9 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Atlanta
Posts: 411
funkytaco is on a distinguished road
Default

farhadf,
DOM is a well-known model; look it up on Wikipedia.

Anyhow, anyone know why I'm getting crashes unless I do this? Maybe it's because I'm in the Simulator?

NSString *title = appDelegate.stringTitle;

NSMutableString *theTitle = [webView stringByEvaluatingJavaScriptFromString:@"document. title"];
if (theTitle) {
txtTitle.text = theTitle;

} else {
txtTitle.text = title;

}
funkytaco is offline   Reply With Quote
Old 05-11-2011, 09:47 AM   #10 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 9
macayer is on a distinguished road
Default

What about if we want to get the data of a pdf from a uiwebview?
macayer is offline   Reply With Quote
Old 05-11-2011, 04:02 PM   #11 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 55
listingboat is on a distinguished road
Default

Quote:
Originally Posted by macayer View Post
What about if we want to get the data of a pdf from a uiwebview?
Can't be done. You need to use Quartz for this. Search for CGPDFDocumentCreateWithURL and CGPDFScannerRef. You'll find examples of parsing PDF files to get the text.

BUT, be warned, parsing PDFs for text is painful. There are strings and string arrays in PDFs, but that doesn't guarantee you can parse a PDF. Some PDFs don't have text at all but use custom "glyphs" to represent characters.

Additionally, you have to handle figuring out if there is a space or not in a string array. You may end up parsing through the array and not finding any spaces. Then you have to look at the distance between characters to figure out where the spaces are.
listingboat is offline   Reply With Quote
Reply

Bookmarks

Tags
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: 356
5 members and 351 guests
bignoggins, Chickenrig, givensur, linkmx, PlutoPrime
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,894
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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