Last active
March 8, 2020 02:07
-
-
Save donvito/183486c9752ab11128f74f32cb0cd23f to your computer and use it in GitHub Desktop.
scrape jobs using colly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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