1

I am connecting to a website, logging in, and grabbing the HTML source of the page with an NSURLRequest, which is working fine. I confirm the html source is what I need by printing it to the console. The problem is that I need to get the rendered HTML after the javascript code finishes. From my research, the only way to do this is by loading that into a UIWebView which I am trying to do. However, when I do this, the webViewDidFinishLoad delegate never fires. Neither does the webViewDidStartLoad. I don't want to display the UIWebView anywhere since its only purpose is to get the rendered HTML for me. Here is my code so far:

import UIKit

class ShowParser : NSObject, UIWebViewDelegate
{
    var webView = UIWebView()

    init()
    {
        super.init()
        webView.delegate = self
        sendRequest()
    }

    funs sendRequest()
    {
        var requestUrl = NSURL(string: "<website>")
        var baseUrl = NSURL(string: "<website>")
        var nsurlRequest = NSMutableURLRequest(URL: requestUrl)
        nsurlRequest.HTTPMethod = "POST"
        nsurlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
        var submitData = "submit=login&lastplace=&email=<username>&password=<password>"
        var requestBodyData = submitData.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
        nsurlRequest.HTTPBody = requestBodyData
        var data = NSURLConnection.sendSynchronousRequest(nsurlRequest, returningResponse: nil, error: nil)
        var dataResultsString = NSString(data: data, encoding: NSUTF8StringEncoding)
        //println(dataResultsString)
        webView.loadHTMLString(dataResultsString, baseURL: baseUrl)
    }

    func webViewDidStartLoad(webView: UIWebView!)
    {
        println("Started Loading")
    }

    func webViewDidFinishLoad(webView: UIWebView)
    {
        println("Finished Loading")
    }
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
PretzelJesus
  • 869
  • 3
  • 11
  • 21

1 Answers1

0

Its been already answered here but incase someone comes across this question then it was just a matter of adding the following:

    theWebPage.delegate = self

I can see you did add it so I assume it was edited already.

Community
  • 1
  • 1
timv
  • 3,346
  • 4
  • 34
  • 43