package main import ( "encoding/json" "fmt" "log" "os" "strings" "github.com/gocolly/colly" ) type job struct { Title string `json:"title"` Logo string `json:"logo"` Company string `json:"company"` Location string `json:"location"` Type string `json:"type"` Description string `json:"description"` Link string `json:"link"` Skills skills `json:"skills"` } type skills struct { React bool `json:"react"` Python bool `json:"python"` Golang bool `json:"golang"` Svelte bool `json:"svelte"` Nextjs bool `json:"nextjs"` Typescript bool `json:"typescript"` Tailwind bool `json:"tailwind"` } func skillChecker(description string) skills { return skills{ React: strings.Contains(description, "React"), Python: strings.Contains(description, "Python"), Golang: strings.Contains(description, "Golang"), Svelte: strings.Contains(description, "Svelte"), Nextjs: strings.Contains(description, "Next.js"), Typescript: strings.Contains(description, "TypeScript"), Tailwind: strings.Contains(description, "Tailwind"), } } func jobsToJson(file *os.File) { // Encode jobs slice to JSON encoder := json.NewEncoder(file) encoder.SetIndent("", " ") // Pretty-print with indentation if err := encoder.Encode(jobs); err != nil { log.Fatalf("Cannot write to file %q: %s", fName, err) } fmt.Println("Job details successfully written to", fName) } // Slice to store job details var ( jobs []job jobCount int maxJobs int = 30 fName string = "jobs.json" ) func main() { file, err := os.Create(fName) if err != nil { log.Fatalf("Cannot create file %q: %s", fName, err) } defer file.Close() baseUrl := "https://thehub.io" searchString := "https://thehub.io/jobs?roles=frontenddeveloper&roles=fullstackdeveloper&roles=backenddeveloper&roles=devops&paid=true&countryCode=DK&sorting=newJobs" // Instantiate default collector c := colly.NewCollector( // visit only the hub colly.AllowedDomains("www.thehub.io", "thehub.io"), // Cache responses to prevent multiple requests colly.CacheDir("./thehub_cache"), ) // Slice of excluded words in the job titles excluded := []string{"senior", "lead"} // Instantiate a new collector to visit the job details page detailsCollector := c.Clone() // On every