-
Notifications
You must be signed in to change notification settings - Fork 0
/
webScrapeViewOG copy.swift
95 lines (84 loc) · 5.92 KB
/
webScrapeViewOG copy.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// WebView.swift
// XavierApp
//
// Created by Eric Li on 7/22/20.
//
import Foundation
import SwiftUI
import WebKit
struct WebView: UIViewRepresentable {
let request: URLRequest
func makeUIView(context _: Context) -> WKWebView {
let webConfiguration = WKWebViewConfiguration()
let webView = WKWebView(frame: .zero, configuration: webConfiguration)
return webView
}
func updateUIView(_ view: WKWebView, context _: Context) {
print(UserDefaults.standard.object(forKey: "Schedule"))
if view.url == nil {
view.load(request)
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
// your code here
view.evaluateJavaScript("document.getElementById('UserName').value='[email protected]';document.getElementById('Password').value='Surddiyi%32';document.getElementsByClassName('btn btn-primary pull-right')[0].click();",
completionHandler: { (_: Any?, _: Error?) in
// print(html)
})
// DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
// view.evaluateJavaScript("document.querySelectorAll('.pointer').length;",
// completionHandler: { (html: Any?, error: Error?) in
// DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
// if let count = html as? Int{
// for i in 0...count {
// DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
// print(i)
// view.evaluateJavaScript("document.getElementsByClassName('pointer')[\(i)].innerHTML;",
// completionHandler: { (html: Any?, error: Error?) in
// print(html)
// })
// }
// }
// }
// }
// })
//
// }
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
view.evaluateJavaScript("window.location.href = 'https://plusportals.com/Print/PrintSchedule?scheduleFor=Student&rotation=9'", completionHandler: { (html: Any?, _: Error?) in
DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
view.evaluateJavaScript("document.querySelectorAll('.schedule-techno').length;",
completionHandler: { (html: Any?, _: Error?) in
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
if var count = html as? Int {
if count >= 16 {
count = 15
}
UserDefaults.standard.set("", forKey: "Schedule")
for i in 0 ... count {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
print(i)
view.evaluateJavaScript("document.getElementsByClassName('schedule-techno')[\(i)].innerHTML;",
completionHandler: { (html: Any?, _: Error?) in
if UserDefaults.standard.string(forKey: "Schedule") != nil {
let temp = UserDefaults.standard.string(forKey: "Schedule")
let stringy = html as? String
let new = temp! + "," + (stringy ?? "")
UserDefaults.standard.set(new, forKey: "Schedule")
} else {
let stringy = html as? String
UserDefaults.standard.set(stringy, forKey: "Schedule")
}
})
}
}
}
}
print(UserDefaults.standard.string(forKey: "Schedule"))
})
}
})
}
}
}
}
}