0

I am programming in Xcode 6 and use objective-c.

I want to load the html code from a page. There are more answers on this questions, but when I try them they only load a part of the page.

I have tried the best answer of the following question: Reading HTML content from a UIWebView

When I try this I only get a part of the HTML string. I even tried:

NSString *html = [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.outerHTML"];

When I view the HTML code on my pc I open firefox and press F12. When I do that I get much more HTML code then from the UIWebView.

Is there any option in UIWebview or even objective-c to get ALL HTML code?

Is it possible to extract mail addresses from the HTML file using Javascript and stringByEvaluatingJavaScriptFromString:?

Community
  • 1
  • 1

1 Answers1

0

You can fetch html of a web page by making a get request to the url of the html and you can get html in a NSString object by using following code . You dont even need UIWebview to access html content of a webpage .

NSURLResponse * response = nil;
NSError * error = nil;

NSURLRequest* urlRequest = [NSURLRequest
                            requestWithURL:[NSURL URLWithString:@"http://www.emdrassociation.org.uk/site.php/profile/emdr/alison_russell.html"]
                                               cachePolicy:NSURLRequestReloadIgnoringCacheData
                                           timeoutInterval:30.0];

NSData* data = [NSURLConnection sendSynchronousRequest:urlRequest  returningResponse:&response error:&error];
NSString *htmlString = [NSString stringWithUTF8String:[data bytes]];
Alper Cinar
  • 861
  • 5
  • 12
  • This option was also told in the link I posted. When I try this I get the same output and I miss a lot of html. –  Oct 22 '14 at 07:07
  • can you give me an example url to test , because i tested with 'http://google.com' and it worked – Alper Cinar Oct 22 '14 at 07:27
  • Random site: http://www.emdrassociation.org.uk/site.php/profile/emdr/alison_russell.html –  Oct 22 '14 at 07:36
  • i copied page source from google chrome and nsstring content to a difference checker it 'only' found 2 difference in entire html which shows that html is generated for each request uniquely , you can see the screen shots http://alpercinar.com/ss/stackoverflow/ss1.png http://alpercinar.com/ss/stackoverflow/ss2.png – Alper Cinar Oct 22 '14 at 07:53
  • And you got that output with the above code? Very strange... Can you post your project? –  Oct 22 '14 at 08:06
  • Yes I know what was going wrong!! When I added an NSLog to give me the NSString is was all the html. I was looking at the string with a breakpoint. That gives a totally different output. So thanks –  Oct 22 '14 at 08:21