-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
41 lines (32 loc) · 791 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
package main
import (
"fmt"
"github.com/caarlos0/env/v6"
"github.com/gocolly/colly"
"github.com/joho/godotenv"
"github.com/tohanilhan/scraper-golang/utils"
"github.com/tohanilhan/scraper-golang/vars"
)
func init() {
err := godotenv.Load(".env")
if err != nil {
fmt.Println("Error loading .env file")
}
err = env.Parse(&vars.Config)
if err != nil {
fmt.Printf("%+v\n", err)
}
}
func main() {
// Instantiate collector with allowed domains
c := colly.NewCollector(
colly.AllowedDomains("dolap.com", "www.dolap.com"),
)
// Create another collector to scrape page count detail
pageCounterCollector := c.Clone()
// Get page count
pageCount := utils.GetPageCount(pageCounterCollector)
// Get all products
utils.GetProducts(c, pageCount)
fmt.Println("Done !")
}