Coder Social home page Coder Social logo

control's Introduction

ecwid-control

control is a automation tool written from scratch using golang on top of Chrome DevTools

Warning This is an experimental project, backward compatibility is not guaranteed!

Installation

go get -u github.com/ecwid/control

How to use

Here is an example of using:

package main

import (
	"context"
	"log"
	"time"

	"github.com/ecwid/control"
	"github.com/ecwid/control/chrome"
)

func main() {
	chromium, err := chrome.Launch(context.TODO(), "--disable-popup-blocking") // you can specify more startup parameters for chrome
	if err != nil {
		panic(err)
	}
	defer chromium.Close()
	ctrl := control.New(chromium.GetClient())
	
	session, err := ctrl.CreatePageTarget("")
	if err != nil {
		panic(err)
	}

	var page = session.Page() // main frame 
	err = page.Navigate("https://surfparadise.ecwid.com/", control.LifecycleIdleNetwork, time.Second*60)
	if err != nil {
		panic(err)
	}

	items, err := page.QuerySelectorAll(".grid-product__title-inner")
	if err != nil {
		panic(err)
	}
	for _, i := range items {
		title, err := i.GetText()
		if err != nil {
			panic(err)
		}
		log.Print(title)
	}
}

You can call any CDP method implemented in protocol package using a session

err = security.SetIgnoreCertificateErrors(sess, security.SetIgnoreCertificateErrorsArgs{
    Ignore: true,
})

or even call a custom method

err = sess.Call("Security.setIgnoreCertificateErrors", sendStruct, receiveStruct)

Subscribe on domain event

cancel := sess.Subscribe("Overlay.screenshotRequested", func(e observe.Value) {
    v := overlay.ScreenshotRequested{}
    _= json.Unmarshal(e.Params, &v)
    doSomething(v.Viewport.Height)
})
defer cancel()

// Subscribe on all incoming events
sess.Subscribe("*", func(e observe.Value) {
    switch e.Method {
        case "Overlay.screenshotRequested":
    }
})

control's People

Contributors

col3name avatar errkeyni avatar retrozoid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

control's Issues

Is it possible to download page html ?

Thanks for great tool :)
I'm trying to download whole page html and I'm stuck.
The code below doesn't work:

html,er:=session.Page.AddScriptToEvaluateOnNewDocument("document.documentElement.outerHTML")
fmt.Println(html) 
//returns 1

Any ideas ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.