所以我有一个叫做lansweeper的工具。它在本地服务器上运行。现在我想从中抓取一个页面,但它使用 Windows 身份验证。
我使用 Powershell 作为脚本语言。
我主要使用HTMLAgilityPack来抓取。但我从来没有抓取过使用 Windows 身份验证的页面。
有谁知道我如何通过它传递我的凭据?以便它在某些凭据下打开页面? (就像我的管理员帐户而不是我的普通帐户)。
(是的,我可以将我的普通用户添加到 Lansweeper 中允许的用户中,但这不是我想使用的解决方案)。
我已经尝试过以下方法,但它不起作用。
[Reflection.Assembly]::LoadFile("C:\Scraping\HtmlAgilityPack\lib\Net45\HtmlAgilityPack.dll”)
[HtmlAgilityPack.HtmlWeb]$web = @{}
$webclient = new-object System.Net.WebClient
$username = "user"
$password = "passw0rd-"
$domain = "mydomain"
$webclient.Credentials = new-object System.Net.NetworkCredential($username, $password, $domain)
[HtmlAgilityPack.HtmlDocument]$doc = $web.Load("http://lansweeper:81/user.aspx?username=sam&userdomain=mydomain","","",$webclient.Credentials)
[HtmlAgilityPack.HtmlNodeCollection]$nodes = $doc.DocumentNode.SelectNodes("//body")
我一直在研究这些功能并发现了两种可能性:
TypeName : HtmlAgilityPack.HtmlWeb
Name : Load
HtmlAgilityPack.HtmlDocument Load(string url),
HtmlAgilityPack.HtmlDocument Load(string url, string proxyHost, int proxyPort, string userId, string password),
HtmlAgilityPack.HtmlDocument Load(string url, string method),
HtmlAgilityPack.HtmlDocument Load(string url, string method, System.Net.WebProxy proxy, System.Net.NetworkCredential credentials)
Name : Get
MemberType : Method
void Get(string url, string path),
void Get(string url, string path, System.Net.WebProxy proxy, System.Net.NetworkCredential credentials),
void Get(string url, string path, string method),
void Get(string url, string path, System.Net.WebProxy proxy, System.Net.NetworkCredential credentials, string method)
但我无法让其中之一工作。有人用 Powershell 做过这个吗?