英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论