Skip to content

cardigann/go-duktape-cheerio

Repository files navigation

go-duktape-cheerio

Load Cheerio into go-duktape.

Usage

First of all install the package go get gopkg.in/olebedev/go-duktape-fetch.v3.

package main

import (
  "fmt"

  "gopkg.in/olebedev/go-duktape.v3"
  "github.com/cardigann/go-duktape-cheerio"
)

func main() {
  // create an ecmascript context
  ctx := duktape.New()

  // push cheerio into the global scope
  cheerio.Define(ctx)

  // use cheerio
  ctx.PevalString(`
    const $ = cheerio.load('<h2 class="title">Hello world</h2>')

    $('h2.title').text('Hello there!')
    $('h2').addClass('welcome')

    $.html()
  `)

  // outputs "<h2 class="title welcome">Hello there!</h2>"
  fmt.Println(ctx.SafeToString(-1))
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published