1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

DOMHTMLElement & DOMNodeList innerHTML property question...

Discussion in 'Mac Programming' started by tradingjam, Jul 22, 2012.

  1. macrumors newbie

    #1
    Hi All,

    Im trying to cycle through a list of all the links on a page... I have a WebView called "myWebView" and have got this far:

    Code:
    [[[self myWebView] mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.bbc.co.uk/news/"]]];
        
        DOMDocument *myDomDocument = [[self myWebView] mainFrameDocument];
        
        DOMNodeList *myList = [myDomDocument getElementsByTagName:@"a"];
    Now Im after the properties InnerHTML and OuterHTML - but these properties look like they're only available in a DOMHTMLElement object....

    So I have a DOMNodeList object called myList, but I want to be able to cycle through them where I can access each node as a DOMHTMLElement object, so that I can get the InnerHTML and OuterHTML properties.

    Any ideas? :confused:

    Ive been picking my brains and searching for the past week, to no avail. Any help would be greatly appreciated!

    Thanks
     
  2. macrumors newbie

    #2
    I figured it out...

    Code:
    - (IBAction)btnDoStuff:(NSButton *)sender {
        [[[self myWebView] mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.bbc.co.uk/news/"]]];
        
        [[self myWebView] setEditable:YES];
       
        
    }
    
    - (IBAction)btnCoolCode:(NSButton *)sender {
        NSMutableArray *myArray = [[NSMutableArray alloc] init];
        
        DOMDocument *myDomDocument = [[self myWebView] mainFrameDocument];
        
        DOMNodeList *myList = [myDomDocument getElementsByTagName:@"a"];
        
        int numElements = [myList length];
        
        for (int i=0; i<numElements; i++) {
            [myArray addObject:(DOMHTMLElement *)[myList item:i]];
        }
            
        self.lblOutput.stringValue = [[myArray objectAtIndex:7] innerText];
     

Share This Page