【问题标题】:VB.NET using Internet Explorer to Automate Saving Websites as HTMLVB.NET 使用 Internet Explorer 将网站自动保存为 HTML
【发布时间】:2013-11-20 22:25:47
【问题描述】:

我正在尝试在 VB.NET 中开发一个简单的工具,该工具在循环中导航到网站并将页面保存为 HTML 文档。

我可以很容易地设置循环,因为页面是按顺序编号的。

www.example.com/pages/1.html
www.example.com/pages/2.html
www.example.com/pages/3.html
www.example.com/pages/4.html

我遇到的麻烦是找到一种方法来保存实际页面。我打算使用一系列 SendKeys 到 Alt、File、Saves As、Enter 等。但我认为必须有某种对象/方法可以用来更直接地做到这一点。

我已启用 COM Internet 控件参考并声明了新的 SHDoc.Vw.InternetExplorer,并且能够以编程方式在新窗口中打开浏览器并导航到所需的页面。我在网上搜索了保存问题的解决方案,但没有成功。有人有什么想法吗?

【问题讨论】:

    标签: html vb.net internet-explorer automation


    【解决方案1】:
    Dim baseUrl As String = "http://www.example.com/pages/{0}.html"
    Dim basePath As String = "C:\some\path{0}.html"
    Using ws As New System.Net.WebClient()
        ForEach i As Integer In Enumerable.Range(1,4)
            wc.DownloadFile(String.Format(baseUrl, i), string.Format(basePath, i))           
        Next i
    End Using
    

    如果您有很多想要花哨的东西,您甚至可以使用DownloadFileAsync() 方法一次排队几个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-24
      • 2017-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-11
      • 2020-11-11
      相关资源
      最近更新 更多