我正在尝试使用从free-proxy-list.net获得的代理刮取一些网站,并使用Golang将其应用到我的本地http请求中,但是当我使用url.Parse()解析代理时,总是返回无效的控制字符URL
func getProxy() *url.URL {
proxyUrl := "https://www.proxy-list.download/api/v1/get?type=http&country=US"
client := &http.Client{}
req, err := http.NewRequest("GET", proxyUrl, nil)
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error proxy ", err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error response body", err)
}
details := string(body)
temp := strings.Split(details, "\n")
fmt.Println("http://" + temp[rand.Intn(30)])
checkProxy, err := url.Parse("http://" + temp[rand.Intn(10)])
if err != nil {
fmt.Println("Bad proxy URL", err)
}
return checkProxy
}
Run Code Online (Sandbox Code Playgroud)