diff options
| author | Philipp Tanlak <philipp.tanlak@gmail.com> | 2023-08-16 19:58:10 +0200 |
|---|---|---|
| committer | Philipp Tanlak <philipp.tanlak@gmail.com> | 2023-08-16 19:58:10 +0200 |
| commit | c36bb2ca2a82338a822c6962f3373809b4bed814 (patch) | |
| tree | d6cb54b7e9d7bf5742b06dedd6bf76eb09ea8385 /js.go | |
| parent | d82e66800478219dd924c6969bd91dbfe004fc9d (diff) | |
add allowed domains feature
Diffstat (limited to 'js.go')
| -rw-r--r-- | js.go | 13 |
1 files changed, 4 insertions, 9 deletions
@@ -58,18 +58,13 @@ func vm(src string) (ScrapeOptions, ScrapeFunc, error) { } var opts ScrapeOptions - - url, err := ctx.RunScript("options.url", "main.js") + optsJSON, err := ctx.RunScript("JSON.stringify(options)", "main.js") if err != nil { - return ScrapeOptions{}, nil, fmt.Errorf("reading options.url: %w", err) + return ScrapeOptions{}, nil, fmt.Errorf("reading options: %w", err) } - opts.URL = url.String() - - depth, err := ctx.RunScript("options.depth", "main.js") - if err != nil { - return ScrapeOptions{}, nil, fmt.Errorf("reading options.depth: %w", err) + if err := json.Unmarshal([]byte(optsJSON.String()), &opts); err != nil { + return ScrapeOptions{}, nil, fmt.Errorf("decoding options json: %w", err) } - opts.Depth = int(depth.Integer()) scrape := func(params ScrapeParams) (any, error) { suffix := randSeq(10) |