Skip to content

Instantly share code, notes, and snippets.

@crgimenes
Last active February 6, 2023 23:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crgimenes/b825cec4fb73fb556380564a440f5dce to your computer and use it in GitHub Desktop.
Save crgimenes/b825cec4fb73fb556380564a440f5dce to your computer and use it in GitHub Desktop.
Web Scraping with Golang
package main
import (
"context"
"log"
"github.com/chromedp/chromedp"
)
func main() {
ctx, cancel := chromedp.NewContext(
context.Background(),
chromedp.WithLogf(log.Printf),
)
defer cancel()
var result string
err := chromedp.Run(ctx,
chromedp.Navigate(`https://golang.org/pkg/time/#example_Date`),
chromedp.WaitVisible(`body > footer`),
chromedp.Click(`
#example_Date >
div.expanded >
div >
div.buttons >
button.Button.Button--primary.run`,
chromedp.NodeVisible),
chromedp.WaitVisible(`
#example_Date >
div.expanded >
div >
div.output >
pre >
span.system`),
chromedp.Text(`
#example_Date >
div.expanded >
div >
div.output >
pre >
span.stdout`,
&result),
chromedp.Stop(),
)
if err != nil {
log.Println(err)
return
}
log.Printf("result %q", result)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment