我想在服务器上运行网页抓取脚本。
当前脚本收集指定页面上的 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 页面中抓取元素。
多谢你们!
这一行将忽略 SSL 证书错误:
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
执行此操作后,有关自签名不受信任证书、名称不匹配或过期的错误将被忽略。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)