-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpage.go
More file actions
39 lines (29 loc) · 653 Bytes
/
page.go
File metadata and controls
39 lines (29 loc) · 653 Bytes
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
package manganatoapi
import (
"fmt"
"github.com/gocolly/colly"
)
type Page struct {
ID string
ImageURL string
}
// use colly to scrape each page's info
func createPages(url string) []Page {
pgs := []Page{}
c.OnHTML(".container-chapter-reader img", func(h *colly.HTMLElement) {
p := Page{}
p.ImageURL = h.Attr("src")
p.getID(p.ImageURL)
pgs = append(pgs, p)
})
c.OnError(func(r *colly.Response, e error) {
fmt.Println("Request URL:", r.Request.URL, "failed with response:", r, "\nError:", e)
})
c.Visit(url)
c.Wait()
return pgs
}
func (p *Page) getID(url string) {
tmp := getID(url, "/")
p.ID = tmp[:len(tmp)-4]
}