|
-
Dec 5th, 2005, 03:10 PM
#1
Thread Starter
Frenzied Member
[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:
Option Explicit
' Use component M$ HTML Object Library
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
Private Function [b]GetFile(URL As String) As String[/b]
'Purpose: returns file title of a URL or local path
GetFile = Right$(URL, Len(URL) - InStrRev(URL, "/"))
End Function
Private Sub [b]Form_Load()[/b]
WebBrowser1.Navigate2 "http://www.yahoo.com"
Dim objDoc1 As HTMLDocument
Dim objDoc2 As HTMLDocument
Dim i As Integer
Set objDoc1 = New HTMLDocument
'Create document element from url
Set objDoc2 = objDoc1.createDocumentFromUrl("http://www.yahoo.com", "")
'Wait till document has loaded
Do While objDoc2.readyState <> "interactive"
DoEvents
Loop
'Loop through images
For i = 0 To objDoc2.images.length - 1
'download images and save them in app.path
URLDownloadToFile 0, objDoc2.images.Item(i).href, App.Path & "\" & GetFile(objDoc2.images.Item(i).href), 0, 0
'MsgBox i
Next i
Set objDoc1 = Nothing
Set objDoc2 = Nothing
Beep
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|