package main
import (
"io/ioutil"
"net/http"
"net/url"
"strings"
)
func main() {
// 获取代理IP
apiURL := "http://api.ip.data5u.com/dynamic/get.html?order=你的提取码&sep=3"
resp, err := http.Get(apiURL)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
// 解析代理IP和端口
ipPort := strings.Split(string(body), ":")
// 使用代理请求目标网页
proxyURL, err := url.Parse("http://" + ipPort[0] + ":" + ipPort[1])
if err != nil {
panic(err)
}
client := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)}}
resp, err = client.Get("http://www.bing.com")
if err != nil {
panic(err)
}
defer resp.Body.Close()
// 读取响应并打印
html, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
print(string(html))
}