我想在服务器上运行一个网络抓取脚本。
当前脚本收集指定页面上的html。
$url = "http://websms"
[net.httpWebRequest] $request = [net.webRequest]::create($url)
[net.httpWebResponse] $response = $request.getResponse()
$responseStream = $response.getResponseStream()
$sr = new-object IO.StreamReader($responseStream)
$result = $sr.ReadToEnd()
$result这在一个典型的网页上工作得很好。然而,我想在一个服务器管理页面上运行它,这当然需要一个登录。
我想在我尝试登录之前,我会尝试抓取服务器的登录页面。运行上面的脚本,我得到了以下结果。
Exception calling "GetResponse" with "0" argument(s): "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."
At C:\temp\web3.ps1:3 char:56
+ [net.httpWebResponse] $response = $request.getResponse <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException任何想法,如何解决这个问题,或者如果你可以指出我一个不同的方向,这样我就可以从服务器的管理html页面中抓取元素。
谢谢你们!
发布于 2012-03-29 09:40:04
下面这行代码将忽略SSL证书错误:
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}执行此操作后,将忽略有关自签名不受信任证书、名称不匹配或过期的错误。
发布于 2012-03-29 09:20:42
public bool AcceptAllCertifications(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certification, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
return true;
}
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);https://stackoverflow.com/questions/9917875
复制相似问题