feat: initial commit
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
// 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)
|
||||
}
|
||||
Reference in New Issue
Block a user