usage in readme
This commit is contained in:
parent
60a35c8a6c
commit
421b3d8f12
18
README.md
18
README.md
|
@ -9,19 +9,31 @@ https://github.com/l0co/docker-puppeteer-api
|
||||||
```go
|
```go
|
||||||
package main
|
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() {
|
func main() {
|
||||||
apiURL := os.Getenv("API_URL")
|
apiURL := os.Getenv("API_URL")
|
||||||
apiSalt := os.Getenv("API_SALT")
|
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 {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
Loading…
Reference in New Issue