Search code examples
iosmobile-safari

download web page source code on iphone


I need to download a particular webpage on my iphone. It redirects me if i use a desktop. Any tools out there that could help me to do this? I have tried sitesucker but it didnt work.

Thanks!


Solution

  • If it redirects you when you use a desktop to access it, you can right click the link and download page as source. But since you want to do it on the iPhone, you can do the following:

    // Download webpage
    NSURL *url = [NSURL URLWithString:@"https://yourURL.here"];
    NSData *urlData = [NSData dataWithContentsOfURL:url];
    [urlData writeToFile:filePath atomically:YES];
    

    And you can access the data through your simulator folder or you directly get the NSString.

    NSURL *url = [NSURL URLWithString:@"https://yourURL.here"];
    NSString *source = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:NULL]