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")
}
}