Jump to content

About image


Recommended Posts

Hi,

I need a function to get the url and src of the images inside a frame

example:

(it's only for explain what i want to say)

<table>

<a href="https://www.autoitscript.com/forum/index.php?amp;">

<img src="https://www.autoitscript.com/forum/style_images/autoit/logo4.gif" style="vertical-align: top;" alt="IPB" border="0">

</a>

<a href="https://www.autoitscript.com/forum/index.php?amp;">

<img src="https://www.autoitscript.com/forum/style_images/autoit/logo4.gif" style="vertical-align: top;" alt="IPB" border="0">

</a>

</table>

i use this code:

$oImgs = _IEImgGetCollection ($oIE)
$iNumImg = @extended
dim $imgarray[$cuenta]
For $oImg In $oImgs
    $imgarray[$cuenta] = $oImg.src
    $cuenta = $cuenta + 1
Next

with this code i get the full src path of each image

but, i need the url too

$oimg.href is the correct way???

sorry about my bad english!!!!!

Link to comment
Share on other sites

Try: $oImg.parantNode.href

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

This should work:

#include <IE.au3>
$oIE = _IECreate ("http://de.selfhtml.org/html/grafiken/anzeige/verweis.htm")
$Imgs = _IEImgGetCollection($oIE)
For $img In $Imgs
    $z = $img.ParentNode
    If $z.tagName = "a" Then MsgBox(0, '', $z.href)
Next
_IEQuit ($oIE)
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Both you and he mispelled "parentNode" !

This worked to get the href's after I saved your html as "xxx.html" in My Documents:

#include <IE.au3>
#include <Array.au3>
$oIE = _IECreate (@MyDocumentsDir & "\xxx.html")
Sleep(3000)
$oImgs = _IEImgGetCollection ($oIE)
Global $pNode
Dim $imgarray[80][2]
Global $i = 0
For $oImg In $oImgs
    $imgarray[$i][0] = $oImg.src
    $pNode = $oImg.parentNode
    $imgarray[$i][1] = $pNode.href
    $i += 1
Next
ReDim $imgarray[$i+1][2]
_ArrayDisplay($imgarray, "src and href")
Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

Both you and he mispelled "parentNode" !

This worked to get the href's after I saved your html as "xxx.html" in My Documents:

#include <IE.au3>
#include <Array.au3>
$oIE = _IECreate (@MyDocumentsDir & "\xxx.html")
Sleep(3000)
$oImgs = _IEImgGetCollection ($oIE)
Global $pNode
Dim $imgarray[80][2]
Global $i = 0
For $oImg In $oImgs
    $imgarray[$i][0] = $oImg.src
    $pNode = $oImg.parentNode
    $imgarray[$i][1] = $pNode.href
    $i += 1
Next
ReDim $imgarray[$i+1][2]
_ArrayDisplay($imgarray, "src and href")

Sorry, but i get the same error.......

Any ideas???

Thanks

Link to comment
Share on other sites

You have to check, if the node is a link tag, so you can't get an error:

#include <Array.au3>
#include <IE.au3>

$oIE = _IECreate ("autoitscript.com")
$oImgs = _IEImgGetCollection($oIE)
Dim $imgarray[80][2]
Global $i = 0
For $oImg In $oImgs
    If $i > 79 Then ReDim $imgarray[$i+1]
    $imgarray[$i][0] = $oImg.src
    $pNode = $oImg.parentNode
    If $pNode.tagName = "a" Then $imgarray[$i][1] = $pNode.href
    $i += 1
Next
ReDim $imgarray[$i][2]

_IEQuit ($oIE)
_ArrayDisplay($imgarray, "src and href")

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Good fix ProgAndy.

Not that it could be needed, but I think you meant something like

If $i > 79 Then ReDim $imgarray[$i+80][2]

instead of

If $i > 79 Then ReDim $imgarray[$i+1]

Das Häschen benutzt Radar

Link to comment
Share on other sites

NO, $i +1 was right.

a) The Array is defined [80] -> index 0...79

:) $i is 80 -> needs REDIM to $i+1 (81) -> maxIndex is 80

c) $i is 81 -> needs REDIM to $i+1 (82) -> maxInedx is 81

...

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

You have to check, if the node is a link tag, so you can't get an error:

#include <Array.au3>
#include <IE.au3>

$oIE = _IECreate ("autoitscript.com")
$oImgs = _IEImgGetCollection($oIE)
Dim $imgarray[80][2]
Global $i = 0
For $oImg In $oImgs
    If $i > 79 Then ReDim $imgarray[$i+1]
    $imgarray[$i][0] = $oImg.src
    $pNode = $oImg.parentNode
    If $pNode.tagName = "a" Then $imgarray[$i][1] = $pNode.href
    $i += 1
Next
ReDim $imgarray[$i][2]

_IEQuit ($oIE)
_ArrayDisplay($imgarray, "src and href")

THANKS, yes really works fine.....

thank you very much friends

Link to comment
Share on other sites

I still think I am correct in that when you use ReDim on an array, that the values in it will be lost if you change the number of dimensions - not that it will matter in this case where I doubt that the page you are parsing has more than 80 images embedded in links.

Also there would be no point in using ReDim in every iteration of the loop, so

... ReDim $imgarray[$i+80][2] is better.

But this line from ProgAndy, is a great fix:

If $pNode.tagName = "a" Then $imgarray[$i][1] = $pNode.href
Edited by Squirrely1

Das Häschen benutzt Radar

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...