+ RenewUseragents()
This commit is contained in:
parent
cd96a9440f
commit
98dbbf54f3
@ -14,7 +14,7 @@ type useragentEntry struct {
|
|||||||
Percentage float64 `json:"pct"`
|
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()
|
var useragents []string = getFreshUseragents()
|
||||||
|
|
||||||
// GetAllUseragents returns all available useragents
|
// GetAllUseragents returns all available useragents
|
||||||
@ -31,6 +31,11 @@ func GetRandomUseragent() string {
|
|||||||
return useragents[r.Intn(len(useragents))]
|
return useragents[r.Intn(len(useragents))]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RenewUseragents scrapes a fresh list of useragents
|
||||||
|
func RenewUseragents() {
|
||||||
|
useragents = getFreshUseragents()
|
||||||
|
}
|
||||||
|
|
||||||
func getFreshUseragents() []string {
|
func getFreshUseragents() []string {
|
||||||
var freshUserAgents []string = []string{}
|
var freshUserAgents []string = []string{}
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ func TestShouldBeValidUseragent(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetFreshUserAgents(t *testing.T) {
|
func TestGetFreshUserAgents(t *testing.T) {
|
||||||
expectedMinimumAmountEntries := 75
|
expectedMinimumAmountEntries := 10
|
||||||
if len(useragents) < expectedMinimumAmountEntries {
|
if len(useragents) < expectedMinimumAmountEntries {
|
||||||
t.Errorf("\ngot: %d\nwanted at least: %d\nfor: len(userAgents)", len(useragents), expectedMinimumAmountEntries)
|
t.Errorf("\ngot: %d\nwanted at least: %d\nfor: len(userAgents)", len(useragents), expectedMinimumAmountEntries)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user