-
Notifications
You must be signed in to change notification settings - Fork 0
/
scraping.go
59 lines (48 loc) · 1.29 KB
/
scraping.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
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"strings"
"github.com/PuerkitoBio/goquery"
)
func check(err error) {
if err != nil {
fmt.Println(err)
}
}
func main() {
url := "https://aws.amazon.com/certification/certified-cloud-practitioner/"
response, error := http.Get(url)
defer response.Body.Close()
check(error)
if response.StatusCode == 200 {
fmt.Println("Stauts code :", response.StatusCode)
}
by, err := ioutil.ReadAll(response.Body)
check(err)
log.Println(string(by))
//s := string(by)
//log.Println(s)
//cont, error := s.Find("id.video-title").Html()
//check(error)
//log.Println((cont))
doc, error := goquery.NewDocumentFromReader(response.Body)
check(error)
filter := func(i int, s *goquery.Selection) bool {
title, _ := s.Attr("href")
return strings.HasPrefix(title, "/watch")
}
var titletext string
doc.Find("div lb-col lb-tiny-24 lb-mid-18").FilterFunction(filter).Each(func(i int, s *goquery.Selection) {
title, _ := s.Attr("href")
titletext = s.Text()
//log.Println(titletext)
_ = title
})
i := strings.Index(titletext, `"refinements":[`)
log.Println(titletext[i:])
//contant := doc.Find("div.section-hero-home-alt-inner-text text-center").Size()
//log.Println(contant)
}