TreeviewCopyright © aleen42 all right reserved, powered by aleen42
Golang
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"net/url"
)
const (
proxyHost = "malenia.iinti.cn"
proxyPort = 24000
proxyUser, proxyPass = "yourProxyAccount", "yourProxyPassword"
targetUrl = `http://myip.ipip.net/`
maxWaitTime = 10
)
func ProxyClient() *http.Transport {
proxyMate := fmt.Sprintf("http://%s:%s@%s:%d", proxyUser, proxyPass, proxyHost, proxyPort)
proxyUrl, err := url.Parse(proxyMate)
if err != nil {
fmt.Println(`Parse proxyMate while error`, err)
}
return &http.Transport{
Proxy: http.ProxyURL(proxyUrl),
}
}
func main() {
client := &http.Client{Transport: ProxyClient()}
request, _ := http.NewRequest("GET", targetUrl, bytes.NewBuffer([]byte(``)))
if response, err := client.Do(request); err != nil {
fmt.Println("failed to connect: " + err.Error())
} else {
bodyByte, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Println("Error reading body:", err)
return
}
response.Body.Close()
body := string(bodyByte)
fmt.Println("Response Body:", body)
}
}
colly
package main
import (
"fmt"
"github.com/gocolly/colly"
"net/http"
"net/url"
)
const (
proxyHost = "malenia.iinti.cn"
proxyPort = 24000
proxyUser, proxyPass = "yourProxyAccount", "yourProxyPassword"
targetUrl = `http://myip.ipip.net/`
maxWaitTime = 10
)
func ProxyTransport() *http.Transport {
proxyMate := fmt.Sprintf("http://%s:%s@%s:%d", proxyUser, proxyPass, proxyHost, proxyPort)
proxyUrl, err := url.Parse(proxyMate)
if err != nil {
fmt.Println(`Parse proxyMate while error`, err)
}
return &http.Transport{
Proxy: http.ProxyURL(proxyUrl),
}
}
func main() {
c := colly.NewCollector(
colly.AllowedDomains("hackerspaces.org", "wiki.hackerspaces.org"),
)
c.WithTransport(ProxyTransport())
c.OnHTML("a[href]", func(e *colly.HTMLElement) {
link := e.Attr("href")
fmt.Printf("Link found: %q -> %s\n", e.Text, link)
c.Visit(e.Request.AbsoluteURL(link))
})
c.OnRequest(func(r *colly.Request) {
fmt.Println("Visiting", r.URL.String())
})
}