[IOS開發]獲取webView中網頁的信息

獲取全部html:NSString *lJs = @"document.documentElement.innerHTML";
獲取網頁title:NSString *lJs2 = @"document.title";
UIWebView *lWebView = [self getCurrentWebView];
NSString *lHtml1 = [lWebView stringByEvaluatingJavaScriptFromString:lJs];
NSString *lHtml2 = [lWebView stringByEvaluatingJavaScriptFromString:lJs2];


JavaScript獲取網頁信息總結
JavaScript獲取當前頁面URL、title等,具體怎麼用就看本身了~
因爲本站用了僞靜態,因此獲取不到文檔名.document.location.port;是獲取URL關聯的端口號碼,thisHash = document.location.hash;是獲取連接屬性中在井號「#」後面的分段。

thisURL = document.URL;
thisHREF = document.location.href;
thisSLoc = self.location.href;
thisDLoc = document.location;
thisTLoc = top.location.href;
thisPLoc = parent.document.location;
thisTHost = top.location.hostname;
thisHost = location.hostname;
thisTitle = document.title;
thisProtocol = document.location.protocol;
thisPort = document.location.port;
thisHash = document.location.hash;
thisSearch = document.location.search;
thisPathname = document.location.pathname;
thisHtml = document.documentElement.innerHTML;
thisBodyText = document.documentElement.innerText;//獲取網頁內容文字
html

相關文章
相關標籤/搜索