|
-
Mar 15th, 2010, 07:54 AM
#1
Thread Starter
New Member
[Resolved] Automatically save all pictures shown in Internet Explorer using VBA macro
Hello,
I am using a Excel VBA macro to control the Internet Explorer (IE = CreateObject("InternetExplorer.Application") ... IE.Navigate ...). Now I would like to save to hard disk all pictures that are currently visible on the IE, WITHOUT navigating again to a special picture-URL (so I cannot use html parsing or Wget-Tools). How to do that?
Many Thanks,
Ursula
Last edited by ursulala; Mar 17th, 2010 at 12:23 PM.
Reason: resolved
-
Mar 15th, 2010, 09:56 AM
#2
Re: Automatically save all pictures shown in Internet Explorer using VBA macro
Thread moved from "VB6" forum to 'Office Development/VBA' forum
-
Mar 15th, 2010, 03:07 PM
#3
Re: Automatically save all pictures shown in Internet Explorer using VBA macro
there is a recent thread, last few months, (or more than one) in the vb6 forum to do exactly this (from a webbrowser control i think), i believe it would still all work in vba, but you will need to do a search to find the thread, i did have some input in the thread
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 15th, 2010, 04:02 PM
#4
Thread Starter
New Member
Re: Automatically save all pictures shown in Internet Explorer using VBA macro
Thank a lot, I see that DragonBay for example had the same problem as I. I will go through that tomorrow as here in Europe it is already late in the evening. I will let you know if problem is fixed.
Good night, Ursula
-
Mar 16th, 2010, 05:53 AM
#5
Addicted Member
Re: Automatically save all pictures shown in Internet Explorer using VBA macro
Get the collection of HTML image elements using GetElementsByTagName("IMG"), then use URLDownloadToFile to download each one. The former function is part of the MS HTML Object library.
-
Mar 16th, 2010, 06:11 AM
#6
Re: Automatically save all pictures shown in Internet Explorer using VBA macro
I see that DragonBay for example
i believe that was the tread i was thinking of
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 16th, 2010, 06:12 AM
#7
Thread Starter
New Member
Re: Automatically save all pictures shown in Internet Explorer using VBA macro
I think, it's not a solution to use URLDownloadToFile since I don't know it's url and it's not stored on the server.
The problem with this image is that it's url is not fixed and it can't be requested for twice from the server cause it's generated automatically every time (it is a validation picture),
so the server doesn't hold a copy of this image...
DragonBoy described the same problem in VB6 forum, I will go through the staff and see whether DragonBoy got a solution.
DragonBoy has already described the same problem in VB6 forum, I will go through the staff and see whether DragonBoy got a solution.
-
Mar 16th, 2010, 03:11 PM
#8
Re: Automatically save all pictures shown in Internet Explorer using VBA macro
And how to do this if verification img does not have a name:
<img src="/sw/verification/verif.php?c=login" alt="captcha" class="captcha"/>
Thanx a lot !
i decided to answer this in your own thread
loop through all the images to find the one with some correct value
vb Code:
for each ele in wb.document.getelementsbytagname("img") if instr(ele.innerhtml, "alt=""captcha""") > 0 then exit for next 'ele i now an object of that specific image
it may be possible that alt is a property of the image, then you could just use
if ele.alt.value = "captcha" then exit for
but i was not sure so used instr
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Mar 17th, 2010, 12:21 PM
#9
Thread Starter
New Member
Re: Automatically save all pictures shown in Internet Explorer using VBA macro
Thanks to all of you, especially to westconn1 !
I use ele.getAttribute("src") instead of ele.innerhtml since the result of innerhtml always was empty. I suppose img is not really a full tag with open and close. Now it works relatively fine, only some fine tuning is still necessary.
Ursula
-
Jan 9th, 2011, 04:18 AM
#10
New Member
Re: [Resolved] Automatically save all pictures shown in Internet Explorer using VBA m
Give you a more simple example. I use msinet to get source form website and after that prasing it
You add
a command button ( and add this following code )
a inet named inet1
a textbox named text1
a listview named lv
Code:
Dim d As Integer
Dim a As String
Dim b() As String
Dim c As Integer
lv.Clear
a = Inet1.OpenURL(Text1.Text)
b = Split(a, "img src=")
For c = 1 To UBound(b)
lv.ItemAdd lv.Count + 1, spt(b(c), """", """")
Next c
lv.ColumnAutosize 1, caItem
Clipboard.Clear
Timer1.Enabled = True
End Function
Function spt(str As String, a As String, b As String)
On Error Resume Next
Dim a1() As String
Dim a2() As String
a1 = Split(str, a)
a2 = Split(a1(1), b)
spt = a2(0)
End Function
I wrote this code in notepad ( I don't have vb6 on my computer ) so it may have some problems. You can modify to suit your purpose
( Sorry for my poor english )
-
Jul 4th, 2011, 11:58 AM
#11
New Member
Re: Automatically save all pictures shown in Internet Explorer using VBA macro
 Originally Posted by westconn1
i decided to answer this in your own thread
loop through all the images to find the one with some correct value
vb Code:
for each ele in wb.document.getelementsbytagname("img")
if instr(ele.innerhtml, "alt=""captcha""") > 0 then exit for
next
'ele i now an object of that specific image
it may be possible that alt is a property of the image, then you could just use
if ele.alt.value = "captcha" then exit for
but i was not sure so used instr
Welcome everybody!
Sorry for digging it up again but Your post was actually the only one that seems to help resolving this problem. I'm struggling on 2 other forums now and try to explain the problem, but no one seems to understand even a bit.
My question is: what actually is returned by this function in varieable "ele"? I think it's something like this:
Code:
ele = <img src="someWWW" alt=captcha"/>
. What code (method, function) let me save it as an image?
Thank You for any help..
-
Jul 4th, 2011, 03:48 PM
#12
Re: [Resolved] Automatically save all pictures shown in Internet Explorer using VBA m
My question is: what actually is returned by this function in varieable "ele"
an object containing the html element from the webpage, with its properties and methods
What code (method, function) let me save it as an image?
if you have the src url from the element, you can use urldownloaedtofile API to save the src to disk
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 5th, 2011, 01:16 AM
#13
New Member
Re: [Resolved] Automatically save all pictures shown in Internet Explorer using VBA m
Thank You for answer!
And will this method save picture that's allready loaded in browser? Because reloading it will completly change the picture...
-
Jul 5th, 2011, 03:37 AM
#14
New Member
Re: [Resolved] Automatically save all pictures shown in Internet Explorer using VBA m
Well, if it can't be saved from IE tamplate maybe it can be save by prinscreen'ing whole site and cropping it to size of disered image? What do you think?
-
Jul 5th, 2011, 03:48 AM
#15
Re: [Resolved] Automatically save all pictures shown in Internet Explorer using VBA m
probably trying to beat captchas, would be against the acceptable use policy of this site
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 5th, 2011, 04:39 AM
#16
New Member
Re: [Resolved] Automatically save all pictures shown in Internet Explorer using VBA m
Well, probably yes, but I'm not the one who has started this topic anyway Apart from that, no one wants to beat captcha, it is in educational purposes only..
-
Jul 5th, 2011, 04:30 PM
#17
Re: [Resolved] Automatically save all pictures shown in Internet Explorer using VBA m
you should be able to copy the picture to clipboard, then save to file
you could try the execwb method of the internet explorer instance to copy the image
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
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
|