在 PowerShell 3.0 中使用 Invoke-Webrequest 会产生 Windows 安全警告 [英] Using Invoke-Webrequest in PowerShell 3.0 spawns a Windows Security Warning

查看:37
本文介绍了在 PowerShell 3.0 中使用 Invoke-Webrequest 会产生 Windows 安全警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 PowerShell 3.0 中使用以下代码时

When using the following code in PowerShell 3.0

PS> $data = Invoke-Webrequest -Uri stackoverflow.com
PS> $data.ParsedHtml.getElementsByTagName("div")

我收到此警告:

Windows 安全警告 - 允许本网站提供信息为您个性化,您是否允许它放置一个小文件(称为 cookie)在你的电脑上?

Windows Security Warning - To allow this website to provide information personalized for you, will you allow it to put a small file (called a cookie) on your computer?

我真的很想抑制此消息或添加处理 cookie 的代码,以便可以安排代码.

I would really like to suppress this message or add code to handle cookies, so the code could be scheduled.

我曾尝试在 IE 中信任该站点,允许 cookie 甚至降低用户帐户控制设置",但无济于事.

I have tried trusting the site in IE allowing cookies and even lowering the "User Account Control Settings" but with no avail.

推荐答案

$data = Invoke-WebRequest http://stackoverflow.com -UseBasicParsing

它看起来像一个 Internet Explorer 提示,这是因为 Invoke-WebRequest 在幕后可能使用 Internet Explorer 来解析 DOM.当您使用 -UseBasicParsing 参数时,您指示 PowerShell 使用它自己的解析器.出于某种原因,它似乎也隐藏了 cookie 提示.

It looks like an Internet Explorer prompt, this is because under the hood Invoke-WebRequest is probably using Internet Explorer to parse the DOM. When you use the -UseBasicParsing parameter you instructing PowerShell to use its own parser. For some reason, it also seems to hide the cookies prompt.

这篇关于在 PowerShell 3.0 中使用 Invoke-Webrequest 会产生 Windows 安全警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆