Reputation: 1145
I am trying to develop a simple tool in VB.NET that, within a loop, navigates to a website and save the page as an HTML document.
I can set up the loop easily as the pages are numbered sequentially.
www.example.com/pages/1.html
www.example.com/pages/2.html
www.example.com/pages/3.html
www.example.com/pages/4.html
Where I am having trouble is with finding a method to save the actual page. I was going to utilize a series of SendKeys to Alt, File, Saves As, Enter, etc.. but I figured there had to be some sort of object/method that could be used to do this more straight forward.
I've enabled the COM Internet Controls Reference and declared and new SHDoc.Vw.InternetExplorer and am able to programatically open the browser in a new window and navigate to the desired page(s). I've search online for a solution to the Save issue but have been unsuccessful. Does anyone have any ideas?
Upvotes: 1
Views: 1144
Reputation: 415665
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
If you have a lot of these want to get a little fancy, you can even use the DownloadFileAsync() method to queue up several of thses at once.
Upvotes: 2