Re: Call getElementById in Cocoa
Re: Call getElementById in Cocoa
- Subject: Re: Call getElementById in Cocoa
- From: Matt Long <email@hidden>
- Date: Mon, 24 Nov 2008 10:27:38 -0700
You can use an NSXMLDocument:
NSString *webpageString = [[[NSString alloc] initWithContentsOfURL:@"http://www.google.com
"] autorelease];
NSError *error = nil;
NSXMLDocument *document = [[NSXMLDocument alloc]
initWithXMLString:webpageString
options:NSXMLDocumentTidyHTML
error:&error];
It doesn't give you the DOM methods, however, XML is easier to parse
than trying to parse the HTML directly.
-Matt
On Nov 24, 2008, at 10:03 AM, Mike Abdullah wrote:
On 24 Nov 2008, at 16:45, John Terranova wrote:
On Nov 24, 2008, at 8:11 AM, Jean-Daniel Dupas wrote:
You call -mainFrameDocument on your WebView to get a DOMDocument
instance, and have access to the DOM functions from here (there is
no up-to-date doc of the Cocoa DOM API, you will have to check
headers files directly to see what function is available, for
example the DOMDocument.h file show you that there is a -
[DomDocument getElementById:] method.
Is it possible to use the DOM functions without first creating the
WebView?
I want to download a webpage and parse its contents without ever
displaying the page. I currently parse the html text directly, but
it is somewhat cumbersome. If I could just walk the DOM structure,
then that would likely be much cleaner.
No, this is not possible. But there is no reason why you have to
present the WebView to the user. Just stick it in an offscreen
window and wait for it to load.
Mike.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden