Results 1 to 7 of 7

Thread: [RESOLVED] Saving Web Page Images In Temp Folder!

Threaded View

  1. #1

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Resolved [RESOLVED] Saving Web Page Images In Temp Folder!

    Using the WebBrowser control, the following code ought to save 'all' images existing in a web page in the user's hard disk (please note that this isn't my code):
    VB Code:
    1. Option Explicit
    2. ' Use component M$ HTML Object Library
    3. Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
    4.  
    5. Private Function [b]GetFile(URL As String) As String[/b]
    6.     'Purpose: returns file title of a URL or local path
    7.     GetFile = Right$(URL, Len(URL) - InStrRev(URL, "/"))
    8. End Function
    9.  
    10. Private Sub [b]Form_Load()[/b]
    11.     WebBrowser1.Navigate2 "http://www.yahoo.com"
    12.    
    13.     Dim objDoc1 As HTMLDocument
    14.     Dim objDoc2 As HTMLDocument
    15.     Dim i As Integer
    16.    
    17.     Set objDoc1 = New HTMLDocument
    18.    
    19.     'Create document element from url
    20.     Set objDoc2 = objDoc1.createDocumentFromUrl("http://www.yahoo.com", "")
    21.    
    22.     'Wait till document has loaded
    23.     Do While objDoc2.readyState <> "interactive"
    24.         DoEvents
    25.     Loop
    26.    
    27.     'Loop through images
    28.     For i = 0 To objDoc2.images.length - 1
    29.         'download images and save them in app.path
    30.         URLDownloadToFile 0, objDoc2.images.Item(i).href, App.Path & "\" & GetFile(objDoc2.images.Item(i).href), 0, 0
    31.         'MsgBox i
    32.     Next i
    33.    
    34.     Set objDoc1 = Nothing
    35.     Set objDoc2 = Nothing
    36.     Beep
    37. End Sub
    There are 2 problems with this code. First, not all the images get saved in the user's hard disk. For e.g. if you navigate to www.yahoo.com, under normal circumstances, 18 images will be saved in IE's Temporary Internet Files folder but the above code only saves 7 images in the folder specified in the code. Any idea how do I overcome this?

    Secondly, have a look at the DoEvents line. Because of this line, it takes about 4-5 seconds for the browser to open up but if the DoEvents line is commented, then the browser opens up in a jiffy but not a single image gets saved in the specified folder. Any idea how do I make the above code work without using DoEvents?

    BTW, what does the Beep in the above code do?

    Thanks,

    Arpan
    Last edited by arpan_de; Dec 5th, 2005 at 08:06 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width