-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnavet.go
48 lines (36 loc) · 1.12 KB
/
navet.go
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
package main
import (
"fmt"
"github.com/gocolly/colly"
)
func scrapeNavet() []Job {
c := colly.NewCollector(colly.AllowedDomains("ifinavet.no"))
detailCollector := c.Clone()
// called before an HTTP request is triggered
c.OnRequest(func(r *colly.Request) {
fmt.Println("Visiting: ", r.URL)
})
c.OnError(func(r *colly.Response, err error) {
fmt.Println("Error while scraping:", err.Error())
})
jobs := []Job{}
c.OnHTML("div.job-card-bottom", func(h *colly.HTMLElement) {
var job Job
job.Title = h.ChildText("h3.job-title")
job.Url = "https://ifinavet.no" + h.ChildAttr("a", "href")
// get the rest of the details from url
jobs = append(jobs, job)
detailCollector.Visit(job.Url)
})
// get deadline
detailCollector.OnHTML("div.event-meta.job-meta:nth-of-type(1) span:nth-of-type(3)", func(h *colly.HTMLElement) {
jobs[len(jobs)-1].Deadline = h.Text
})
// get company name
detailCollector.OnHTML("div.company-info", func(h *colly.HTMLElement) {
jobs[len(jobs)-1].Company = h.ChildText("h2")
fmt.Println(jobs[len(jobs)-1].Company)
})
c.Visit("https://ifinavet.no/stillingsannonser/")
return jobs
}