orb

package module
v0.0.0-...-f1094a2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: MIT Imports: 6 Imported by: 0

README

Orb

Go Report Card Go Reference test workflowGitHub license

Orb is heavily inspired by Cheerio.js, a elegant solution to traversing/manipulating the DOM model. That being said, Orb combines the power of Go and the API of Cheerio to produce a easy and fast library for gophers.

Table of Contents

Project Status

Currently Orb is stil a work in progress and should not be used for production apps.

Installation

Please make sure that your Go version is v1.1+

$ go get github.com/anthonygedeon/orb

Usage

To see more examples and documentation, please visit godoc.org

package main

import (
    "fmt"
    "net/http"

    "github.com/anthonygedeon/orb"
)

func main() {
    resp, err := http.Get("https://golang.org/dl/")
    if err != nil {
        fmt.Errorf("invalid get request: %s", err)
    }
    defer resp.Body.Close()

    if resp.StatusCode != http.StatusOK {
        fmt.Errorf("status error: %v", resp.StatusCode)
    }

    body, err := io.ReadAll(resp.Body)
    if err != nil {
        fmt.Errorf("invalid body content: %s", err)
    }

    doc := string(body)

    o := o.Load(doc)
    
    o(".downloadtable .download").Each(func(i int, node *orb.Query) {
        textNode := node.Text()
        fmt.Println(textNode)
    })
}

Contributing

First off, I'm glad that you would like to contribute to Orb :)

To contribute please take a look at the contribution guide for instructions.

License

Orb is released under the MIT License. See LICENSE

Documentation

Overview

Package orb provides primitives for scraping HTML from web pages

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(document string) func(sel string) *Query

Load

Types

type Document

type Document struct {
	// contains filtered or unexported fields
}

Document

type Query

type Query struct {
	Node *html.Node
	// contains filtered or unexported fields
}

Query

func (*Query) AddAttr

func (qs *Query) AddAttr()

AddAttr

func (*Query) AddClass

func (qs *Query) AddClass(className string) *Query

AddClass

func (*Query) Append

func (qs *Query) Append()

Append

func (*Query) Attr

func (qs *Query) Attr()

Attr

func (*Query) Children

func (qs *Query) Children() *Query

Children

func (*Query) Data

func (qs *Query) Data(target string) string

Data

func (*Query) Each

func (qs *Query) Each(fn func(i int, node *Query))

Each

func (*Query) Filter

func (qs *Query) Filter(selector string)

Filter

func (*Query) Find

func (qs *Query) Find(sel string) *Query

Find

func (*Query) FindAll

func (qs *Query) FindAll(sel string) *Query

FindAll

func (*Query) HasClass

func (qs *Query) HasClass(target string) bool

HasClass

func (*Query) Html

func (qs *Query) Html()

Html BUG(https://github.com/golang/go/issues/23487) renders duplicate html

func (*Query) Index

func (qs *Query) Index()

Index

func (*Query) Is

func (qs *Query) Is()

Is

func (*Query) Map

func (qs *Query) Map(fn func(i int, node *html.Node))

Map

func (*Query) Next

func (qs *Query) Next() *Query

Next

func (*Query) NextAll

func (qs *Query) NextAll() *Query

NextAll

func (*Query) NextAllFilter

func (qs *Query) NextAllFilter(selector string) *Query

NextAllFilter

func (*Query) NextUntil

func (qs *Query) NextUntil(selector string) *Query

NextUntil

func (*Query) Parent

func (qs *Query) Parent() *Query

Parent

func (*Query) ParentFilter

func (qs *Query) ParentFilter(selector string) *Query

ParentFilter

func (*Query) Parents

func (qs *Query) Parents() *Query

Parents

func (*Query) ParentsFilter

func (qs *Query) ParentsFilter(selector string) *Query

ParentsFilter

func (*Query) ParentsUntil

func (qs *Query) ParentsUntil(selector string) *Query

ParentsUntil

func (*Query) Prev

func (qs *Query) Prev() *Query

Prev

func (*Query) PrevAll

func (qs *Query) PrevAll() *Query

PrevAll

func (*Query) PrevAllFilter

func (qs *Query) PrevAllFilter(selector string) *Query

PrevAllFilter

func (*Query) PrevUntil

func (qs *Query) PrevUntil(selector string) *Query

PrevUntil

func (*Query) Remove

func (qs *Query) Remove() *Query

Remove

func (*Query) RemoveAttr

func (qs *Query) RemoveAttr()

RemoveAttr

func (*Query) RemoveClass

func (qs *Query) RemoveClass() *Query

RemoveClass

func (*Query) Text

func (qs *Query) Text() string

Text

func (*Query) ToggleClass

func (qs *Query) ToggleClass()

ToggleClass

Notes

Bugs

  • renders duplicate html

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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