-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdoc.go
68 lines (67 loc) · 1.63 KB
/
doc.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
60
61
62
63
64
65
66
67
68
// Package spider offers a way to scrape websites.
// Installation:
//
// go get -u github.com/celrenheit/spider
//
//
// Usage of this package is around the usage of spiders and passing contexts.
//
//
// ctx, err := spider.Setup(nil)
// err := spider.Spin(ctx)
//
// If you have many spider you can make use of a scheduler. This package provides a basic scheduler.
//
// scheduler := spider.NewScheduler()
//
// scheduler.Add(schedule.Every(20 * time.Second), spider1)
//
// scheduler.Add(schedule.Every(20 * time.Second),spider2)
//
// scheduler.Start()
//
// This will launch 2 spiders every 20 seconds for the first and every 10 seconds for the second.
//
//
// You can create you own spider by implementing the Spider interface
//
//
// package main
//
// import (
// "fmt"
//
// "github.com/celrenheit/spider"
// )
//
// func main() {
// wikiSpider := &WikipediaHTMLSpider{
// Title: "Albert Einstein",
// }
// ctx, _ := wikiSpider.Setup(nil)
// wikiSpider.Spin(ctx)
// }
//
// type WikipediaHTMLSpider struct {
// Title string
// }
//
// func (w *WikipediaHTMLSpider) Setup(ctx *spider.Context) (*spider.Context, error) {
// url := fmt.Sprintf("https://en.wikipedia.org/wiki/%s", w.Title)
// return spider.NewHTTPContext("GET", url, nil)
// }
//
// func (w *WikipediaHTMLSpider) Spin(ctx *spider.Context) error {
// if _, err := ctx.DoRequest(); err != nil {
// return err
// }
//
// html, _ := ctx.HTMLParser()
// summary := html.Find("#mw-content-text p").First().Text()
//
// fmt.Println(summary)
// return nil
// }
//
//
package spider