55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
// Command anubis-smoke is a throwaway tool: it solves the Anubis challenge for
|
|
// a URL and writes the resulting page to stdout (or a file), so we can inspect
|
|
// the real scoreboard HTML and pin scraper selectors.
|
|
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
"log/slog"
|
|
"os"
|
|
|
|
"git.mkz.me/mycroft/root-me-api/internal/anubis"
|
|
)
|
|
|
|
func main() {
|
|
url := flag.String("url", "https://www.root-me.org/?page=classement&lang=en", "URL to fetch")
|
|
out := flag.String("out", "", "write body to this file (default stdout)")
|
|
flag.Parse()
|
|
|
|
slog.SetLogLoggerLevel(slog.LevelDebug)
|
|
|
|
tr, err := anubis.New()
|
|
if err != nil {
|
|
fatal(err)
|
|
}
|
|
resp, err := tr.Client().Get(*url)
|
|
if err != nil {
|
|
fatal(err)
|
|
}
|
|
defer resp.Body.Close()
|
|
body, err := io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
fatal(err)
|
|
}
|
|
|
|
fmt.Fprintf(os.Stderr, "status=%d bytes=%d\n", resp.StatusCode, len(body))
|
|
|
|
w := os.Stdout
|
|
if *out != "" {
|
|
f, err := os.Create(*out)
|
|
if err != nil {
|
|
fatal(err)
|
|
}
|
|
defer f.Close()
|
|
w = f
|
|
}
|
|
w.Write(body)
|
|
}
|
|
|
|
func fatal(err error) {
|
|
fmt.Fprintln(os.Stderr, "error:", err)
|
|
os.Exit(1)
|
|
}
|