gomine

package module
v0.0.0-...-0fd12eb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2018 License: MIT Imports: 9 Imported by: 0

README

alt text

GoMine

A web scraping library written in Golang.

Table of Contents

Installation

Download to your $GOPATH using Go CLI:

go get github.com/itstc/gomine

Usage

Gathering Data from a website, first request the .html file and then find the target using GoMine's Find/FindAll functions

Example:

// request the html document you want to scrape
var client http.Client
resp, err := client.Get("https://github.com/itstc/gomine")
if err != nil {
	log.Fatal(err)
}
defer resp.Body.Close()

// parse into an html.Node
root, err := html.Parse(resp.Body)
if err != nil {
	log.Fatal(err)
}

// using the root html.Node we can find all filenames with query: tr>td.content>span>a
results := gomine.FindAll(root, "tr>td.content>span>a")
for i, result := range results {
	fmt.Println(i, result.FirstChild.Data)
}

The result gives you the file names in the go-mine repository

0 .gitignore
1 LICENSE
2 README.md

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExportToJSON

func ExportToJSON(filename string, mapping interface{}) error

ExportToJSON takes a mapping and writes to filename

func Find

func Find(root *html.Node, element string) *html.Node

Find finds and return the first Node that contains element

func FindAll

func FindAll(root *html.Node, element string) []*html.Node

FindAll finds and return the first Node that contains element

func GetRootByURL

func GetRootByURL(url string) *html.Node

GetRootByURL returns a root node of html page if url is valid

func Partition

func Partition(root *html.Node, query string) (*html.Node, error)

Partition returns first element found in a query

Types

type Stack

type Stack struct {
	Array   []interface{}
	Current int
	Size    int
	sync.Mutex
}

Stack object allows goroutines for pushing/popping data while handling race conditions

func NewStack

func NewStack(a ...interface{}) *Stack

NewStack initializes a new stack

func (*Stack) AsyncPop

func (s *Stack) AsyncPop(wg *sync.WaitGroup) interface{}

AsyncPop takes the most recent value out of the stack

func (*Stack) AsyncPush

func (s *Stack) AsyncPush(value interface{}, wg *sync.WaitGroup)

AsyncPush appends a value into the stack

func (*Stack) IsEmpty

func (s *Stack) IsEmpty() bool

IsEmpty checks if stack is empty

func (*Stack) Pop

func (s *Stack) Pop() interface{}

Pop takes the most recent value out of the stack

func (*Stack) Push

func (s *Stack) Push(value interface{})

Push appends a value into the stack

type Worker

type Worker struct {
	PageRoot *html.Node
	Task     func(root *html.Node) map[string]interface{}
}

Worker scrapes a url by given task

func (*Worker) Execute

func (w *Worker) Execute(wg *sync.WaitGroup) interface{}

Execute the task with given url

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL