-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (35 loc) · 743 Bytes
/
main.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
package main
import (
"encoding/csv"
"fmt"
"log"
"os"
"strconv"
"github.com/gocolly/colly/v2"
)
func main() {
fName := "data.csv"
file, err := os.Create(fName)
if err != nil {
log.Fatalf("Could not create file, err : %q", err)
return
}
defer file.Close()
writer := csv.NewWriter(file)
defer writer.Flush()
c := colly.NewCollector(
colly.AllowedDomains("internshala.com"),
)
c.OnHTML(".internship_meta", func(h *colly.HTMLElement) {
writer.Write([]string{
h.ChildText("a"),
h.ChildText("span"),
})
})
for i := 0; i < 190; i++ {
fmt.Printf("Scraping page : %d\n", i)
c.Visit("https://internshala.com/internships/page-" + strconv.Itoa(i))
}
log.Printf("Scraping Completed\n")
log.Println(c)
}