Sign in to follow this  
Followers 0
brodie28

Downloading an image from a webpage

16 posts in this topic

#1 ·  Posted (edited)

How would I download an image from a webpage that changes each time the page is loaded?

Using InetGet does not work because when it downloads the image, it has changed. I need it to download the image that is displayed when the page is loaded, the same as right clicking on it and using "save as" would.

EDIT: It doesn't necessarily need to download the image, but I need to be able to imbed it into a GUI.

Edited by brodie28

Share this post


Link to post
Share on other sites



There have been one or two discussions of this. One is here: IE UDFs - Save image from a html page.

I recall that the person eventually told me (perhaps in a PM) that they had found a workaround, but I never saw wat it was.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Does the IE.au3 UDF hold any hope? Parse the source and you have the file location to save with an InetGet.

[edit] Dale (the author of IE.au3 - kudos to him) beat me to it! [/edit]

Edited by Confuzzled

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Does the IE.au3 UDF hold any hope? Parse the source and you have the file location to save with an InetGet.

[edit] Dale (the author of IE.au3 - kudos to him) beat me to it! [/edit]

I'm assuming this is a random image that although it changes it always has the same URL. The only possible way I could think of doing this would be to pull the image from the browser cache. However I looked into this with the last topic Dale mentioned, but I was never able to come up with anything. Edited by big_daddy

Share this post


Link to post
Share on other sites

@Confuzzled ;-)

Another thing to consider is that the file will exist in your browser cache, but I don't know of any interface taht allows you to find it easily.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

i thought almost the same as Confuzzled

inetgetsource ( to a file )

parse file ( actually hoping just the first time will show which line number in the file)

then $info = filereadliine()

$info2 = stringbetween( $info, "http://www.website/,,,/", ".bmp")

inetget("http://www.website/,,,/" & $info2 & ".bmp,....)

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

@Val

I think the trouble is that the image that they want to get changes each time they connect to the page -- and they want the one that is displayed at the moment. InetGet initiates a new connection to the server each time (and the image changes even though the URL is the same).

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

brodie28: What is the webpage you are trying so desperately to suck images from?

Maybe turn this problem over and look at it from the other end - instead of getting your browser to display the webpage and then realise you have missed the image of a lifetime, why not get AutoIT to fetch it first and then display it to see if that is the one you want and discard it if it is not? Alternatively, you could always embed the image inside a local web page you have generated from AutoIT and refresh the contents using the functions in the IE.au3 UDF.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

@Val

I think the trouble is that the image that they want to get changes each time they connect to the page -- and they want the one that is displayed at the moment. InetGet initiates a new connection to the server each time (and the image changes even though the URL is the same).

Dale

@Dale..

I thought you would understand how this could work. Yes the initial URL does not change ( hopefully ) and that is why i would use inetgetsource from the constant URL

if the "pic" changes, hopefully it would remain on the same line number in downloaded file each time

then you could get a string between the "http//www." and the ".bmp" ( if it is a bmp )

then use inetget "http//www." & $the_string_between & ".bmp"

i have done it.... it could work

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Example.... if a number changes

; Get the Latest Beta
; Author - Valuater

#include <INet.au3>
$NBeta = _INetGetSource('http://www.autoitscript.com/autoit3/files/beta/autoit/')
For $x = 500 to 104 Step -1
    If StringInStr( $NBeta, "autoit-v3.1.1."& $x & "-beta-Setup.exe") Then
        $NBeta = "autoit-v3.1.1."& $x & "-beta-Setup.exe"
        ExitLoop
    EndIf
    If $x <= 105 Then
        MsgBox(262208, "Beta Error", "No File Found.   ", 5)
        Return
    EndIf
Next
MsgBox(0,'',$NBeta)
; use InetGet()

there is anothere in the examples for Welcome to Autoit 1-2-3... i will get that one too

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

here it is

; demonstration to find chracters that change between to standard points
; or just find a string
#include <IE.au3>

#Region --- IE-Builder generated code Start ---

$oIE = _IECreate ()

;------------- User input --------------
_IENavigate ($oIE, "http://www.autoitscript.com/") ; web address
$Find = "LZ" ; my info shows after this line... or just find this line
$Before = "comp"    ; my info shows before this line... or set as ""
; ------------ End User input -------------
Sleep(1000)
$body =  _IEBodyReadHTML ($oIE)
$sloc = @TempDir & "\stest.txt"
FileDelete($sloc)
FileWrite($sloc, $body)
$sfile = FileOpen($sloc, 0)
$num = 0
While 2
    $num = $num + 1
    $sline = FileReadLine($sfile, $num)
    If @error Then
        MsgBox(262208, "Fail", "The string was NOT found   ")
        FileClose($sfile)
        Exit
    EndIf
    If StringInStr($sline, $Find) Then
        MsgBox(64, "Success", "The string " & $Find & " was found    " & @CRLF & " on line # " & $num, 5)
        If $Before = "" Then ExitLoop
        $Found = stringbetween($sline, $Find, $Before)
        MsgBox(64, "Found", "The string is " & $Found & "    ", 5)
        ExitLoop
    EndIf
WEnd

Func stringbetween($str, $start, $end)
    $pos = StringInStr($str, $start)
    If Not @error Then
        $str = StringTrimLeft($str, $pos + StringLen($start) - 1)
        $pos = StringInStr($str, $end)
        If Not @error Then
            $str = StringTrimRight($str, StringLen($str) - $pos + 1)
            Return $str
        EndIf
    EndIf
EndFunc   ;==>stringbetween

#EndRegion --- IE-Builder generated code End ---

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

@Val

I think the trouble is that the image that they want to get changes each time they connect to the page -- and they want the one that is displayed at the moment. InetGet initiates a new connection to the server each time (and the image changes even though the URL is the same).

Dale

just noticed this....

InetGet initiates a new connection to the server each time

maybe your right... but the last pic should still work.... it still has a valid URL ( hopefully )

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Presumably one could invoke the "Save Page" feature either through the object model if such a method exists or via basic Window automation. That would save both the page and all images. Then it would be possible to find the file on disk.

Share this post


Link to post
Share on other sites

If there was a way to download the entire webpage automaticly (at the moment all that is possible is opening a save as dialogue box) then maybe I could search through the images it saved....

Do you think saving images through the object model will ever be implemented in IE Dale?

Share this post


Link to post
Share on other sites

Did you actually try the suggestions?

In InetGet you have the option to fetch the browser cached version, which I think is what you are wanting.

Even a 'save as' will have to go out and fetch the file.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

If there was a way to download the entire webpage automaticly (at the moment all that is possible is opening a save as dialogue box) then maybe I could search through the images it saved....

Do you think saving images through the object model will ever be implemented in IE Dale?

No, not through the browser object model anyway. The fact is that you can invoke the Save As function using the browser object model and there is actually a noPrompt option documented that would allow you to fully script the operation, but the functionality was removed for security reasons -- so it always puts up a save as dialog.

So, you can do this with windows automation or a combination of COM and windows automation.

Regarding InetGet... if you haven't already I think you should do some testing with it. Pulling from cache is its default action, so it may work. The example I placed in the snippet database would help you figure out the url of the image and invoke InetGet on it -- I don't know what happens if the page specifies CACHE-CONTROL:NO-CACHE however. Please post your testing results.

Dale

Edit: typos ans snippet url

Edited by DaleHohm

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0