From 98dbbf54f3d6773832f92ee07180ced801b89387 Mon Sep 17 00:00:00 2001 From: Andreas Schulte <0x0001f346@pm.me> Date: Wed, 17 Jan 2024 22:33:57 +0100 Subject: [PATCH] + RenewUseragents() --- useragents.go | 7 ++++++- useragents_test.go | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/useragents.go b/useragents.go index 254c626..dbe0592 100644 --- a/useragents.go +++ b/useragents.go @@ -14,7 +14,7 @@ type useragentEntry struct { Percentage float64 `json:"pct"` } -var defaultUseragent string = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36" +var defaultUseragent string = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.3" var useragents []string = getFreshUseragents() // GetAllUseragents returns all available useragents @@ -31,6 +31,11 @@ func GetRandomUseragent() string { return useragents[r.Intn(len(useragents))] } +// RenewUseragents scrapes a fresh list of useragents +func RenewUseragents() { + useragents = getFreshUseragents() +} + func getFreshUseragents() []string { var freshUserAgents []string = []string{} diff --git a/useragents_test.go b/useragents_test.go index 4e7b067..75a5d00 100644 --- a/useragents_test.go +++ b/useragents_test.go @@ -116,7 +116,7 @@ func TestShouldBeValidUseragent(t *testing.T) { } func TestGetFreshUserAgents(t *testing.T) { - expectedMinimumAmountEntries := 75 + expectedMinimumAmountEntries := 10 if len(useragents) < expectedMinimumAmountEntries { t.Errorf("\ngot: %d\nwanted at least: %d\nfor: len(userAgents)", len(useragents), expectedMinimumAmountEntries) }