Erik是一款基于WebKit的无界面浏览器,可用于功能函数的测试,使用JavaScript对网页进行操作访问。
示例(使用Google搜索):
let url = NSURL(string:"https://www.google.com")!let value = "Erik The Phantom of Opera"// visitvar future: Future<Document, NSError> = Erik.visitURLFuture(url)// fill input fieldfuture = future.flatMap { document -> Future<Document, NSError> in if let input = document.querySelector("input[name='q']") { input["value"] = value } if let form = document.querySelector("form[name=\"f\"]") as? Form { form.submit() } return Erik.currentContentFuture()}// finally get final result as success or errorfuture.onSuccess { document in // parse result}future.onFailure { error in print("\(error)")}
评论