puppeteerapiclient/README.md

49 lines
774 B
Markdown
Raw Permalink Normal View History

2024-06-02 18:32:29 +00:00
# puppeteer api client
This is a golang client for the api exposed by the puppeteer docker container.
https://github.com/l0co/docker-puppeteer-api
# usage
```go
package main
2024-06-02 18:37:25 +00:00
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"
2024-06-02 18:32:29 +00:00
func main() {
apiURL := os.Getenv("API_URL")
apiSalt := os.Getenv("API_SALT")
2024-06-02 18:37:25 +00:00
client := puppeteerapiclient.NewClient(apiURL, apiSalt)
2024-06-02 18:32:29 +00:00
2024-06-02 18:37:25 +00:00
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
2024-06-02 18:32:29 +00:00
2024-06-02 18:37:25 +00:00
defer cancel()
2024-06-02 18:32:29 +00:00
2024-06-02 18:37:25 +00:00
response, err := client.Scrape(ctx, url, selector)
2024-06-02 18:32:29 +00:00
2024-06-02 18:37:25 +00:00
if err != nil {
log.Fatal(err)
}
fmt.Println(response.Content)
2024-06-02 18:32:29 +00:00
}
```
# License
WTFPL