Jump to content

IE UDFs - Save image from a html page


Recommended Posts

I don't like to use inet coz it actually need to open up a new browser to grab the picture. I would want to grab picture from the current html page that I have focus on.

Step 1 - attach to the particular html that I have open or open the page with create function

$oIE = _IEAttach ("http://www.autoitscript.com", "URL")

Step 2 - Get obj reference to the image file on that page

$oImgs = _IEImgGetCollection ($oIE)

$x = 0

For $oImg In $oImgs

If StringinStr($oImg.src, "logo4") Then

MsgBox(0, "Img Info", $x&" - src=" & $oImg.src)

$o_Imgs = _IEImgGetCollection ($oIE, $x)

EndIf

$x = $x + 1

Next

Step 3 - Download that file (now this is a part I am stuck on). Is there any particular command that I can use over here that could grab that logo file and save it directly to a file on my desktop? And no I don't want to save the whole html file using _IEAction "saveas" command, more direct way if any.

Be glad if anyone could answer. If there isn't anyway I guess might need to work around it...

Link to comment
Share on other sites

Inetget will open up a different browser - don't want that :D.

Since I hate to make a whole character definition for OCR on a certian website, what I am going to do is pop out that particular image for me to enter just the digits then continue for the page to load while I am doing my work.

With Inetget it will actually open up a new browser to grab just that particular image and what happen next is that the image actually reloaded with another image

Link to comment
Share on other sites

I don't like to use inet coz it actually need to open up a new browser to grab the picture. I would want to grab picture from the current html page that I have focus on.

Step 1 - attach to the particular html that I have open or open the page with create function

$oIE = _IEAttach ("http://www.autoitscript.com", "URL")

Step 2 - Get obj reference to the image file on that page

$oImgs = _IEImgGetCollection ($oIE)

$x = 0

For $oImg In $oImgs

If StringinStr($oImg.src, "logo4") Then

MsgBox(0, "Img Info", $x&" - src=" & $oImg.src)

$o_Imgs = _IEImgGetCollection ($oIE, $x)

EndIf

$x = $x + 1

Next

Step 3 - Download that file (now this is a part I am stuck on). Is there any particular command that I can use over here that could grab that logo file and save it directly to a file on my desktop? And no I don't want to save the whole html file using _IEAction "saveas" command, more direct way if any.

Be glad if anyone could answer. If there isn't anyway I guess might need to work around it...

Here's a hybrid solution:

#include <IE.au3>

$sImgDir = "c:\foo\"; Please make certain this folder already exists (silent failure if not)
$sWebPage = "http://www.autoitscript.com/forum/index.php?"; webpage with images

$oIE = _IECreate( $sWebPage)
$oIMGs = _IEImgGetCollection ($oIE)

; Loop through all IMG tags and save file to local directory using INetGet
For $oIMG in $oIMGs
    $sImgUrl = $oIMG.src
    $sImgFileName = $oIMG.nameProp
    INetGet($sImgUrl,  $sImgDir & $sImgFileName)
Next

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

Link to comment
Share on other sites

  • Moderators

don't work. tested with inetget, it tend to open up new browser so it will just mess the picture supposely for security purpose.

It does work, did you change the $sImgDir? Look at the note Dale provided. I've used Inetget several times and it has never oped a browser window.
Link to comment
Share on other sites

... it can't be used. because inetget will open up a new bowser to copy that particular image. If the new image will not be refresh each time I got no problem on it. However for security code (where OCR is needed) the picture will get refresh each time a new browser is open so the picture you saw on your HDD will not be the same as the one you saw on the website.

This however can be solve by downloading the whole webpage with IEAction() then open the image file but I am just wondering if there is any easier way to grab the image directly.

Link to comment
Share on other sites

Ah... terminology... InetGet doesn't open a new browser, but it opens a new connection to the webserver -- this is your trouble right?

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

Link to comment
Share on other sites

I can think of no easy way to do this. For security reasons the browser does not allow a way to script a save operation. You can do it for the full document, but a saveas dialog is displayed.

You could use a .focus method on the image, then send a right-click to the browser and use AutoIt core functions to choose Save As and manipulate the resulting dialog.

You could also potentially do a screen capture and save the result (there are ways of getting the position of the object on the screen, but they are complicated and I have read they are buggy).

So, it should be possible, but it will depend on how motivated you are to work through it.

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

Link to comment
Share on other sites

  • 2 years later...

Hello

Is there a chance some new solution came up since this post in 2006? :)

I am stuckw ith this problem too,

Saving the Image with INetGet(), is actually downloading the image via another process(AutoIt3.exe process), which does not have a firewall right to access the internet, and more.

If someone has a solution that simply gets the Image that is already here, since the Attached IE window downloaded it already,

please write..

Thanks

Link to comment
Share on other sites

_IEPropertyGet now allows you to get the screen coordinates of an element.

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

Link to comment
Share on other sites

_IEPropertyGet now allows you to get the screen coordinates of an element.

Hi Dale

So I will get the image coordinates, and then do screencapture on them..

mmm..

definately possible, altho I fear to lose image quality.

But I guess there's no other way?

So weird that IE does not enable me to simply get the image object and save it....

Edited by Zohar
Link to comment
Share on other sites

  • 1 year later...

BUMP,

Same problem here. At this point i use something like this:

#include <ScreenCapture.au3>
#include <ie.au3>


$oie = _IEAttach("My Webpage test for Imagedownload")

$oImg = _IEImgGetCollection ($oIE, 1)
local $Xpos = _IEPropertyGet($oImg, "screenx")
local $Ypos = _iepropertyget($oimg, "screenY")
WinActivate("My Webpage test for Imagedownload")
$iWidth = _IEPropertyGet($oimg, "width")
$iHeight = _IEPropertyGet($oimg, "height")

MsgBox(0,"", $xpos)
MsgBox(0,"", $Ypos)
MsgBox(0,"", $iWidth)
MsgBox(0,"", $iHeight)
; Capture region
_ScreenCapture_Capture("C:\blah.jpg", $xpos +3 , $ypos+3, $xpos + 400, $ypos + 150)

But when i RESIZE the browser other than fullscreen then it captures the wrong coordinates.

Maybe you seem to think that this is logical, because i use ScreenX and ScreenY but it also captures the wrong region when i use BrowserX and BrowserY.

Does anyone have a better solution since 2006?

Thanks in advance.

Link to comment
Share on other sites

  • 7 months later...
  • 3 years later...

HI  GUY

 i  have  a  question  i try to use   InetGet  for  download image  from site  but  dont  go and  when   i use option  , $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)

i have  this  error

(36) : ==> Variable used without being declared.:

for  $inet_forcereload 

i thinked probably i miss  a  include   but i  use  ,   this is  my include

; Script Start - Add your code below here

#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <IE.au3>

 

my  autoit version is 

AutoIt Version: 3.3.12.0

Edited by faustf
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...