Powerschool is a site that keeps track of letter days to indicate lab days for my high school. It also keeps track of people's grades, but I just want to scrape the letter day.
So I am trying to access info contained on html off the site https://pschool.princetonk12.org/guardian/home
To do that I must login through this portal https://pschool.princetonk12.org/public/ which uses oauth.
I know I have to use an authentication token and I see it printed in the output. How do I make a session on https://pschool.princetonk12.org/guardian/home to ultimately parse through it? How do I get the token and use it? Thanks so much!
Here is what I have so far:
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()