Update scraper.go
Support auth for SetProxy socks5
This commit is contained in:
parent
e63ee5fdc2
commit
1f4290bd5c
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,
|
||||
KeepAlive: s.client.Timeout,
|
||||
}
|
||||
socksHostPort := strings.ReplaceAll(proxyAddr, "socks5://", "")
|
||||
dialSocksProxy, err := proxy.SOCKS5("tcp", socksHostPort, nil, baseDialer)
|
||||
proxyURL, err := url.Parse(proxyAddr)
|
||||
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 {
|
||||
return errors.New("error creating socks5 proxy :" + err.Error())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue