From 421b3d8f1290aaa26b4fe615965c55bbc58637d7 Mon Sep 17 00:00:00 2001 From: sneak Date: Sun, 2 Jun 2024 11:37:25 -0700 Subject: [PATCH] usage in readme --- README.md | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 41db0b1..163eb39 100644 --- a/README.md +++ b/README.md @@ -9,24 +9,36 @@ https://github.com/l0co/docker-puppeteer-api ```go package main -import "fmt" +import ( + "context" + "fmt" + "log" + "os" + "time" + + _ "github.com/joho/godotenv/autoload" + "sneak.berlin/go/puppeteerapiclient" +) + +const url = "https://news.ycombinator.com" +const selector = ".athing .title .titleline" func main() { apiURL := os.Getenv("API_URL") apiSalt := os.Getenv("API_SALT") - client := NewClient(apiURL, apiSalt) + client := puppeteerapiclient.NewClient(apiURL, apiSalt) - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() + defer cancel() - response, err := client.Scrape(ctx, "https://news.ycombinator.com", ".athing .title") + response, err := client.Scrape(ctx, url, selector) - if err != nil { - log.Fatal(err) - } - fmt.Println(response.Content) + if err != nil { + log.Fatal(err) + } + fmt.Println(response.Content) } ```