Golang网络爬虫NTLM身份验证

huangapple go评论93阅读模式
英文:

Golang web scraper NTLM authentication

问题

一个 Golang 网页爬虫需要从一个需要 NTLM 认证的网页中提取信息。

有一个有效的用户名和密码,网页爬虫如何与服务器执行 NTLM 4 次握手,以便获得对受保护网页的访问权限?

url, username, password := "http://www.some-website.com", "admin", "12345"

client := &http.Client{}
req, _ := http.NewRequest("GET", url, nil)
req.Header.Set("Authorization", "NTLM")
res, _ := client.Do(req)
英文:

A Golang web scraper needs to extract information from a webpage that is NTLM-authenticated.

Having a valid username & password, how can the web scraper perform the NTLM 4-way handshake with the server in order to gain access to the protected webpage behind?

url, username, password := "http://www.some-website.com", "admin", "12345"

client := &http.Client{}
req, _ := http.NewRequest("GET", url, nil)
req.Header.Set("Authorization", "NTLM")
res, _ := client.Do(req)

答案1

得分: 4

你可以使用Azure/go-ntlmssp这样的包在开始爬取之前进行身份验证。

url、username、password := "http://www.some-website.com", "admin", "12345"

client := &http.Client{
    Transport: ntlmssp.Negotiator{
        RoundTripper: &http.Transport{},
    },
}

req, _ := http.NewRequest("GET", url, nil)
req.SetBasicAuth(username, password)

res, _ := client.Do(req)
英文:

You can use a package like Azure/go-ntlmssp to authenticate before you start scraping.

url, username, password := "http://www.some-website.com", "admin", "12345"

client := &http.Client{
    Transport: ntlmssp.Negotiator{
        RoundTripper:&http.Transport{},
    },
}

req, _ := http.NewRequest("GET", url, nil)
req.SetBasicAuth(username, password)

res, _ := client.Do(req)

huangapple
  • 本文由 发表于 2016年11月8日 21:48:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/40488583.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定