【问题标题】:Open url from script on Windows Server 2008从 Windows Server 2008 上的脚本打开 url
【发布时间】:2010-10-16 00:49:49
【问题描述】:

我想编写一个自动加载 url(例如http://google.com)的脚本。但我不想在服务器上安装任何第 3 方库或程序。最简单的方法是什么?

我只是我的选项是批处理脚本、vb 脚本或 powershell 对吗?

【问题讨论】:

    标签: powershell vbscript batch-file


    【解决方案1】:

    来自 PowerShell 的仅供参考,如果您想检索 URL 的内容,您可以这样做;

    $page = (new-object net.webclient).DownloadString("http://www.bing.com")
    $page # writes the contents to the console
    

    如果你只是想在浏览器中打开它:

    Start-Process http://www.bing.com
    

    或者使用起始别名

    start http://www.bing.com
    

    Start-Process 是 PowerShell 2.0 中的新功能。

    【讨论】:

      【解决方案2】:

      Powershell 的美妙之处在于它有很多方法可以做某事。

      这是我的 Powershell 2.0 示例代码 - 包含一个暂停功能以允许网站打开。它使用 Internet Explorer 作为浏览器。在这种情况下 - IE 是比其他浏览器更好的浏览器,因为它通过详细的 API 与 Powershell 集成。

      $url = "http://www.google.com/"
      $ie = new-object -com "InternetExplorer.Application"
      $ie.Navigate($url)
      

      这个对象有很多不同的功能。我建议加载 Powershell 命令行,输入上面的代码,然后检查该对象还有哪些其他功能。输入 $ie。并按 TAB 遍历该库的所有方法。

      我对 Powershell 了解得越多,它就越令人兴奋。它在 Windows 上没有什么不能做的。

      【讨论】:

        【解决方案3】:

        你可以使用 vbscript

        url="http://somewhere.com"
        Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
        objHTTP.Open "GET", url, False
        objHTTP.Send
        wscript.Echo objHTTP.ResponseText
        objFile.Close
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-05-11
          • 1970-01-01
          • 1970-01-01
          • 2013-02-14
          相关资源
          最近更新 更多