Merge pull request #152 from laikee99/Auth-for-SetProxy
Update scraper.go
This commit is contained in:
commit
fdd172a136
1 changed files with 14 additions and 2 deletions
16
scraper.go
16
scraper.go
|
|
@ -130,8 +130,20 @@ func (s *Scraper) SetProxy(proxyAddr string) error {
|
||||||
Timeout: s.client.Timeout,
|
Timeout: s.client.Timeout,
|
||||||
KeepAlive: s.client.Timeout,
|
KeepAlive: s.client.Timeout,
|
||||||
}
|
}
|
||||||
socksHostPort := strings.ReplaceAll(proxyAddr, "socks5://", "")
|
proxyURL, err := url.Parse(proxyAddr)
|
||||||
dialSocksProxy, err := proxy.SOCKS5("tcp", socksHostPort, nil, baseDialer)
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// username password
|
||||||
|
username := proxyURL.User.Username()
|
||||||
|
password, _ := proxyURL.User.Password()
|
||||||
|
|
||||||
|
// ip and port
|
||||||
|
host := proxyURL.Hostname()
|
||||||
|
port := proxyURL.Port()
|
||||||
|
|
||||||
|
dialSocksProxy, err := proxy.SOCKS5("tcp", host+":"+port, &proxy.Auth{User: username, Password: password}, baseDialer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("error creating socks5 proxy :" + err.Error())
|
return errors.New("error creating socks5 proxy :" + err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue