【问题标题】:Saving a web page from IE using Powershell使用 Powershell 从 IE 保存网页
【发布时间】:2010-10-26 17:50:33
【问题描述】:

我使用来自 Powershell 的 Internet Explorer 的自动化界面以支持的格式打开网页。我想以 IE 支持的一种格式将此页面保存回磁盘。打开页面很简单:

$ie = New-Object -ComObject "InternetExplorer.Application"
$ie.Navigate("C:\MyFile.mht")

如何以另一种格式保存它?

我需要一个不提示用户的解决方案,因为我的想法是在运行多个文件的脚本中自动执行此操作。

【问题讨论】:

    标签: .net internet-explorer powershell automation


    【解决方案1】:

    You want to call ExecWB with the appropriate args:

    $ie.ExecWB(4,0,$null,[ref]$null)
    

    4个参数的解释:

    4 = OLECMDID_SAVEAS
    0 = OLECMDEXECOPT_DODEFAULT (This can also be 2 = OLECMDEXECOPT_DONTPROMPTUSER to not prompt and just save)
    $null = NULL (I think this can be a path to save to: separate folders with 2 slashes (\\))
    [ref]$null = ref NULL :)
    

    【讨论】:

    • 谢谢!我可以直接在参数 3 中指定文件名和扩展名(文件类型)。但我仍然得到对话框提示,即使使用“2”(DONTPROMPTUSER)。这意味着我无法在使用多个文件的脚本中自动执行此操作。你知道解决这个问题的方法吗?
    猜你喜欢
    • 1970-01-01
    • 2015-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-13
    • 2012-06-13
    • 1970-01-01
    • 2018-05-15
    相关资源
    最近更新 更多