问题
I am trying to get the HTML source of a UIWebView without re-downloading it again (a.k.a. do another download, such as [NSData dataWithContentsOfURL:(NSURL*)URL] or launching an NSURLRequest. Browsing the UIWebView header and documentation, there seems to be no way of accessing the current loaded NSData of the source. Am I missing something ?
回答1:
The inverse should do what you want. That is, load the URL into an NSData object and then load the UIWebView from that object using – loadData:MIMEType:textEncodingName:baseURL:
回答2:
UIWebView can execute javascript code, so this can work it out.
NSString *html = [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.outerHTML"];
来源:https://stackoverflow.com/questions/3044041/uiwebview-get-html-source