在PowerShell 3.0中使用Invoke-Webrequest会产生Windows安全警告 [英] Using Invoke-Webrequest in PowerShell 3.0 spawns a Windows Security Warning
问题描述
在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屋!