Created
October 3, 2023 16:20
-
-
Save 0xJohnnyGault/7e11de30380c13ae54f328d22682e155 to your computer and use it in GitHub Desktop.
Go Headless
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module github.com/multisig-labs/go-headless | |
go 1.20 | |
require ( | |
github.com/chromedp/cdproto v0.0.0-20230914224007-a15a36ccbc2e | |
github.com/chromedp/chromedp v0.9.2 | |
) | |
require ( | |
github.com/chromedp/sysutil v1.0.0 // indirect | |
github.com/gobwas/httphead v0.1.0 // indirect | |
github.com/gobwas/pool v0.2.1 // indirect | |
github.com/gobwas/ws v1.2.1 // indirect | |
github.com/josharian/intern v1.0.0 // indirect | |
github.com/mailru/easyjson v0.7.7 // indirect | |
golang.org/x/sys v0.6.0 // indirect | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"log" | |
"strings" | |
"time" | |
"github.com/chromedp/cdproto/dom" | |
"github.com/chromedp/chromedp" | |
) | |
func main() { | |
// You need google-chrome installed and in your path | |
ctx, cancel := chromedp.NewContext( | |
context.Background(), | |
) | |
defer cancel() | |
var html string | |
ok := false | |
err := chromedp.Run(ctx, | |
chromedp.Navigate("https://app.gogopool.com/create-minipool/"), | |
// wait for the page to load | |
chromedp.Sleep(2000*time.Millisecond), | |
// extract the raw HTML from the page | |
chromedp.ActionFunc(func(ctx context.Context) error { | |
// select the root node on the page | |
rootNode, err := dom.GetDocument().Do(ctx) | |
if err != nil { | |
return err | |
} | |
html, err = dom.GetOuterHTML().WithNodeID(rootNode.NodeID).Do(ctx) | |
// Look for a string on the page that would only be there if things worked | |
ok = strings.Contains(html, "Register a node") | |
return err | |
}), | |
) | |
if err != nil { | |
log.Fatal("Error while performing the automation logic:", err) | |
} | |
fmt.Println(ok) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment