PowerShell 技能连载 - 访问网页内容

从 PowerShell 3.0 开始,Invoke-WebRequest 命令可以轻松地下载网页内容。例如这个例子可以从 www.powertheshell.com 获取所有链接:

#requires -Version 3

$url = 'http://www.powertheshell.com'
$page = Invoke-WebRequest -Uri $url
$page.Links

您也可以用这种方式获取原始的 HTML 内容:

#requires -Version 3

$url = 'http://www.powertheshell.com'
$page = Invoke-WebRequest -Uri $url
$page.RawContent

当您用这种方法处理其它 URL 时,您可能偶尔会遇到弹出一个安全警告框,提示需要存储 cookie 的权限。要禁止这些对话框出现并静默执行命令,请使用 -UseBasicParsing 参数。

PowerShell 技能连载 - 访问网页内容

http://blog.vichamp.com/2015/09/16/accessing-web-page-content/

作者

吴波

发布于

2015-09-16

更新于

2022-07-06

许可协议

评论