Powerschool 是一个跟踪字母日期的网站,以指示我高中的实验室日期。它还跟踪人们的成绩,但我只想刮信一天。
所以我试图从网站https://pschool.princetonk12.org/guardian/home访问 html 中包含的信息
为此,我必须通过 使用 oauth 的门户https://pschool.princetonk12.org/public/登录。
我知道我必须使用身份验证令牌,并且我看到它打印在输出中。如何在https://pschool.princetonk12.org/guardian/home上进行会话以最终解析它?如何获取令牌并使用它?非常感谢!
这是我到目前为止所拥有的:
import Foundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
let credential = URLCredential(user: "username", password: "password", persistence: URLCredential.Persistence.forSession)
let protectionSpace = URLProtectionSpace(host: "pschool.princetonk12.org", port: 443, protocol: "https", realm: "Restricted", authenticationMethod: NSURLAuthenticationMethodHTTPBasic)
URLCredentialStorage.shared.setDefaultCredential(credential, for: protectionSpace)
let config = URLSessionConfiguration.default
let session = URLSession(configuration: config)
let url = URL(string: "https://pschool.princetonk12.org/public/.json")!
let task = session.dataTask(with: url) { (data, response, error) in
guard error == nil else {
print(error?.localizedDescription ?? "")
return
}
print(String(data: data!, encoding: .utf8))
}
task.resume()