2016-01-21 53 views

回答

0

更新的解決方案:這是醜陋的,但工程。該網站要求你跳過一些箍來使用它,但secondURL將加載一個只是表格的頁面。

這絕對是一個更清潔的解決方案,它不需要JS或多個頁面加載,但我把它留給你。

我發現secondURL通過查找Safari的網絡督察

import UIKit 

private let firstURL = NSURL(string: "https://legymnase67.la-vie-scolaire.fr/vsn.main/;jsessionid=E2D99A46028465A9D7F636521C64088B.node2?autolog=70caa4a471e8f6f0856735aed506b01a6307246c445beb160259f75c1c700f7978631d698cc5e0e890452bd182e5960e6153be7c4a3d2615ff0daf981a17877d46e472cdf2ef2328977c3957a58121e3556c4b9b808e22a76d0cbb994292a2144d64f367714c7dfbf4d3e24cea5f0274")! 
private let secondURL = NSURL(string: "https://legymnase67.la-vie-scolaire.fr/vsn.main/releveNote/releveNotes")! 

class WebController: UIViewController, UIWebViewDelegate { 

    let webView: UIWebView = UIWebView() 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     self._setupWebView() 

     // load the webpage, wait 6 seconds then tap the button 
     webView.loadRequest(NSURLRequest(URL: firstURL)) 
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(6 * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), { 
      self.tapButton(); 

      // wait another 4 seconds then load the direct notes url 
      dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(4 * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), { 
       self.webView.loadRequest(NSURLRequest(URL: secondURL)) 

       // allow the page to load, and print the html 
       dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(4 * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), { 
        print(self.webView.stringByEvaluatingJavaScriptFromString("document.body.innerHTML")) 
       }) 
      }) 
     }) 
    } 

    func tapButton() { 
     webView.stringByEvaluatingJavaScriptFromString("changeIframeSrc(this, 'NOTES');") 
    } 

    func _setupWebView() { 
     webView.translatesAutoresizingMaskIntoConstraints = false 
     self.view.addSubview(webView) 

     let views = ["webView":webView] 
     self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[webView]|", options: [], metrics: nil, views: views)) 
     self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[webView]|", options: [], metrics: nil, views: views)) 
    } 
} 
+0

由於它是工作!! :)但我怎麼能現在得到的顯示頁面的HTML代碼?因爲當我嘗試,這是打印歡迎頁面的HTML代碼 – Jbr

+0

它看起來,HTML不會在頁面之間變化 – Casey

+0

是lt當我檢查使用Safari中的開發人員工具 – Jbr

0

你可以在你的應用程序的網絡視圖中插入JavaScript,如果你用一個顯示頁面

如果你使用一個UIWebView的使用方法stringByEvaluatingJavaScriptFromString(jscodestring)

如果使用WKWebView使用方法evaluateJavaScript( jscodestring)

然後這是一個javascript問題。

  • 首先看元素點擊:文檔。 getElementById或getElementByName,document.querySelector等...

  • 然後使用html dom方法click();