getting HTML source code

Discussion in 'Mac Programming' started by aatif, Jun 2, 2008.

  1. aatif macrumors newbie

    Joined:
    May 26, 2008
    #1
    hello,

    Is there any way to get the source code of the webpage that is being displayed by the webview? Assume that I've provided the URL of this page.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Yes, it's all in the documentation. Also it's very bad form to tag a question onto someone else's thread. Instead of hijacking their thread start your own.

    The following will get the source code as part of a web frame load delegate:

    Code:
    - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
    {
    	if (frame == [sender mainFrame] ||
    		[frame parentFrame]==nil)
    	{
    		source = [[[[[webView mainFrame] dataSource] representation] documentSource] retain];
    	}
    }
    
    Note that I only want the source from the main frame of the webview and check that this is the case.
     
  3. aatif thread starter macrumors newbie

    Joined:
    May 26, 2008
    #3
    Thanx for ur help and guidance, however I got the solution as;

    Code:
    NSString *source = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"www.website.com"]];
    
     

Share This Page