@@ -58,6 +58,11 @@ func downloadFile(new_qp qpRaw) {
58
58
defer file .Close ()
59
59
}
60
60
61
+ func sanitizeFilename (s string ) string {
62
+ // replaces all spaces with _
63
+ return strings .ReplaceAll (s , "%20" , "_" )
64
+ }
65
+
61
66
func main () {
62
67
63
68
c := colly .NewCollector (
@@ -81,13 +86,13 @@ func main() {
81
86
return
82
87
}
83
88
link := e .Attr ("href" )
84
- url := e .Request .AbsoluteURL (link )
89
+ file_url := e .Request .AbsoluteURL (link )
85
90
var name string
86
91
var year int
87
92
var exam_type string
88
93
89
- if strings .Contains (url , ".pdf" ) {
90
- temp := strings .Split (url , "/" )
94
+ if strings .Contains (file_url , ".pdf" ) {
95
+ temp := strings .Split (file_url , "/" )
91
96
name = temp [len (temp )- 1 ]
92
97
year , _ = strconv .Atoi (temp [4 ])
93
98
exam_type = strings .ToLower (temp [5 ])
@@ -105,13 +110,13 @@ func main() {
105
110
}
106
111
}
107
112
108
- new_qp = append (new_qp , qpRaw {strings .Join (temp [4 :], "_" ), name , year , exam_type , url })
113
+ new_qp = append (new_qp , qpRaw {sanitizeFilename ( strings .Join (temp [4 :], "_" )) , name , year , exam_type , file_url })
109
114
}
110
115
111
116
c .Visit (e .Request .AbsoluteURL (link ))
112
117
})
113
118
114
- c .Visit ("http://10.18.24.75/peqp" )
119
+ c .Visit ("http://10.18.24.75/peqp/2024 " )
115
120
c .Wait ()
116
121
117
122
file , err := os .Create ("qp.csv" )
0 commit comments