Skip to content

Instantly share code, notes, and snippets.

@donvito
Last active March 8, 2020 02:07
Show Gist options
  • Save donvito/183486c9752ab11128f74f32cb0cd23f to your computer and use it in GitHub Desktop.
Save donvito/183486c9752ab11128f74f32cb0cd23f to your computer and use it in GitHub Desktop.
scrape jobs using colly
package main
import (
"fmt"
"github.com/gocolly/colly/v2"
)
func main() {
c := colly.NewCollector(
colly.AllowedDomains("www.indeed.com.sg", "indeed.com.sg", "sg.indeed.com"),
)
c.OnHTML("div.jobsearch-SerpJobCard", func(e *colly.HTMLElement) {
jobTitle := e.ChildText("a.jobtitle")
fmt.Printf("Job title: %s\n", jobTitle)
companyName := e.ChildText("span.company")
fmt.Printf("Company: %s\n", companyName)
location := e.ChildText("span.location")
fmt.Printf("Location: %s\n", location)
salary := e.ChildText("span.salaryText")
fmt.Printf("Salary: %s\n\n", salary)
summary := e.ChildText("div.summary")
fmt.Printf("Summary: %s\n\n", summary)
})
//parse first 5 pages
c.Visit("https://sg.indeed.com/jobs?q=golang&l=Singapore&jt=permanent")
c.Visit("https://sg.indeed.com/jobs?q=golang&l=Singapore&start=10")
c.Visit("https://sg.indeed.com/jobs?q=golang&l=Singapore&start=20")
c.Visit("https://sg.indeed.com/jobs?q=golang&l=Singapore&start=30")
c.Visit("https://sg.indeed.com/jobs?q=golang&l=Singapore&start=40")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment