saving images

leontager

Well-known member
Joined
Jun 17, 2003
Messages
89
Hi, how can I save all the images on a webpage? Similarly to when you do it manually and IE creates the HTML file and a seperate folder for all the images.

I think it will have something to do with this

Dim htImg As mshtml.HTMLImg
Dim obDC As mshtml.HTMLDocument
Dim ITEM As Object
Dim obIE As SHDocVw.InternetExplorer

For Each htImg In obDC.images.item
somehow save it
Next

obviously this doesnt work :-)
but can someone please tell me how to make it work
 
like this maybe .....
Code:
    Private doc As mshtml.HTMLDocument

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AxWebBrowser1.Navigate("http://google.com")
    End Sub

    Private Sub AxWebBrowser1_DocumentComplete(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent) Handles AxWebBrowser1.DocumentComplete
        doc = DirectCast(AxWebBrowser1.Document, mshtml.HTMLDocument)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Not doc Is Nothing Then
            Dim img As mshtml.HTMLImg

            For Each img In doc.images
                If img.href <> "" Then
                    Dim wc As New Net.WebClient()
                    wc.DownloadFile(img.href, "C:\" & img.href.Split("/")(img.href.Split("/").GetUpperBound(0)))
                End If
            Next
        End If
    End Sub
 
wow thank you very much

you can also use this

Dim myRequest As WebRequest = WebRequest.Create(address)
Dim bmp As Bitmap = Bitmap.FromStream(myRequest.GetResponse().GetResponseStream())
bmp.save(path)
 
I altered your example a little (only added url parsing for file saving, progress bar fix, and added a percentage label), and whenever I use it or the original, my computer begins to lag badly and the example acts a like a non responsive program, but I can still see the progress bar go up. However when its done, it all goes back to normal. Is there any way to prevent this? I can download it all in one chunk, but then theres no progress bar :( (unless I checked the file size of the file while it was still being downloaded, but Im guessing it would produce the same laggy results).

-> I just tried using DownloadFile() all by itself with no size checks, etc and it still lags and acts non responsive... why? I thought that would go faster... :(
 
Last edited by a moderator:
Back
Top