Go to file
2024-06-02 11:37:25 -07:00
.gitignore initial 2024-06-02 11:32:29 -07:00
client_test.go initial 2024-06-02 11:32:29 -07:00
client.go initial 2024-06-02 11:32:29 -07:00
go.mod initial 2024-06-02 11:32:29 -07:00
go.sum initial 2024-06-02 11:32:29 -07:00
LICENSE initial 2024-06-02 11:32:29 -07:00
Makefile initial 2024-06-02 11:32:29 -07:00
README.md usage in readme 2024-06-02 11:37:25 -07: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

package main

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 := puppeteerapiclient.NewClient(apiURL, apiSalt)

	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)

	defer cancel()

	response, err := client.Scrape(ctx, url, selector)

	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(response.Content)
}

License

WTFPL