html - Powershell Web 抓取 SSL/TLS 问题

标签 html powershell web-scraping

我想在服务器上运行网络抓取脚本。

当前脚本采集指定页面的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}

关于自签名不受信任的证书、不匹配的名称或过期的错误将在执行后被忽略。

关于html - Powershell Web 抓取 SSL/TLS 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9917875/

相关文章:

html - 如何在列表项中添加偏移量?

powershell - 如何使用 PowerShell 定义计划任务的到期日期

java - "view page source"上不可见的 html 元素

html - XPath地址不够详细

python - 返回网页内容之前等待

html - 检查单选按钮样式兄弟标签

javascript - 当我打开模态时,导航栏会越过模态?

html - 表格 - 电话号码验证

.net - 为什么 "net use */delete"不起作用但在我的 PowerShell 脚本中等待确认?

PowerShell:新时间跨度格式结果