Last active
February 6, 2023 23:18
-
-
Save crgimenes/b825cec4fb73fb556380564a440f5dce to your computer and use it in GitHub Desktop.
Web Scraping with Golang
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" | |
"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