Chaining Functions
MasterSwift opened this issue · comments
I wanted to know if it was possible for me to chain different scrapes. Modifying the example, you can see what I mean. Also, it would be cool know how to get the current url and pass it to the next function
func getProvisioningProfiles(_ url: URL, user: String, password: String) {
open(url)
>>* get(by: .id("account name")
>>> setAttribute("value", value: user)
>>* get(by: .id("account password")
>>> setAttribute("value", value: password)
>>* get(by: .name("form2"))
>>> submit(then: .wait(2.0))
>>* get(by: .contains("href", "/account/"))
>>> click(then: .wait(2.5))
>>* getAll(by: .contains("class", "row-"))
=== getSomeOtherInfo
}
func getSomeOtherInfo(_ url: URL) {
open(url2)
>>* get(by: .id("account name")
>>> setAttribute("value", value: user)
>>* get(by: .id("account password")
>>> setAttribute("value", value: password)
>>* get(by: .name("form2"))
>>> submit(then: .wait(2.0))
>>* get(by: .contains("href", "/account/"))
>>> click(then: .wait(2.5))
>>* getAll(by: .contains("class", "row-"))
=== handleResult
}
//========================================
// MARK: Handle Result
//========================================
func handleResult(_ result: Result<[HTMLTableRow]>) {
switch result {
case .success(let value): self.outputResult(value)
case .error(let error): self.handleError(error)
}
}
func outputResult(_ rows: [HTMLTableRow]) {
let columns = rows.flatMap { $0.columns?.first }
performSegue(withIdentifier: "detailSegue", sender: columns)
}
func handleError(_ error: ActionError) {
print("Error loading page: \(error)")
loginButton.isEnabled = true
activityIndicator.stopAnimating()
dump()
clearCache()
}
```))))
Hey @MasterSwift. Sorry for the late response. If you still have questions, feel free to reopen or create a new issue. Thanks!
did you work out how to do this @MasterSwift