Jump to content

_IEImgGetCollection fails...


SeratN
 Share

Recommended Posts

Hi, I've been working on a script that downloads pictures from deviantART the last few days. Now I'm stuck and can't find any way to solve this :)

The script will only download the pictures from the first page, it can't find the rest of the pictures...

Here is an example:

#include <IE.au3>

$Result = _DownloadDeviantArt()
MsgBox(0, "DA Downloader!", $Result)

Func _DownloadDeviantArt()
    $HidPicForm = GUICreate("Downloading...", 400, 400)
    $Obj = _IECreateEmbedded()
    $ActiveX = GUICtrlCreateObj($Obj, 10, 10, 380, 380)
    $s = 1
    For $i = 1 To 6 ; First page is fine, the rest is not :(
        _IENavigate($Obj, "http://penguina-mica.deviantart.com/gallery/#_featured--" & $i)
        _IELoadWait($Obj)
        $oImgs = _IEImgGetCollection($Obj)
        For $oImg In $oImgs
            If $oImg.src = "http://penguina-mica.deviantart.com/gallery/" And $oImg.height = 0 And $oImg.width = 0 Then ; Check for pics that are disabled. (I.E. not logged in)
                GUIDelete($HidPicForm)
                Return "Not logged in. Please logg in via IE."
            EndIf
        Next
        $oImgs = _IEImgGetCollection($Obj)
        For $oImg In $oImgs
            If $oImg.src = "http://penguina-mica.deviantart.com/gallery/" Or $oImg.height < 25 And $oImg.width < 25 Then ; Sort out DA original pics.
                $s = $s - 1
            Else
                $Result = StringInStr($oImg.src, ".jpg")
                If Not $Result = 0 Then
                    $StringSplit = StringReplace($oImg.src, "http://th", "http://fc") ; Replace preview adress with real adress.
                    $DownloadString = StringReplace($StringSplit, "/150/i/", "/i/") ; Same ^
                    $Download = InetGet($DownloadString, @ScriptDir & "\Pics\Pic" & $s & ".jpg")
                Else
                    $s = $s - 1
                EndIf
            EndIf
            $s = $s + 1
            If $s >= 25 Then ExitLoop ; I can only display 24 pics per page.
        Next
    Next
    GUIDelete($HidPicForm)
    Return "Complete."
EndFunc

If you try to run the code (with a folder named "Pics") you'll see that it only downloads the first 24 pics.

Any help would be appreciated ;)

/SeratN

Link to comment
Share on other sites

Hi, SeratN

I was looking for some way to get images from a website by src and came across your code

I have not implemented the code for my use yet, but I repaired your code so it now downloads 115 pics from 5 pages (current count as of today)

I have posted the code below with the changes commented out with ****** signs

See if this helps in any way

#include <IE.au3>

$Result = _DownloadDeviantArt()

MsgBox(0, "DA Downloader!", $Result)

Func _DownloadDeviantArt()

$HidPicForm = GUICreate("Downloading...", 400, 400)

$Obj = _IECreateEmbedded()

$ActiveX = GUICtrlCreateObj($Obj, 10, 10, 380, 380)

$s = 1

For $i = 1 To 5 ; First page is fine, the rest is not :)

_IENavigate($Obj, "http://penguina-mica.deviantart.com/gallery/#_featured--")

_IELoadWait($Obj)

;************* ADDED **************

If _IELoadWait($Obj) = 0 Then

_IENavigate($Obj, "http://penguina-mica.deviantart.com/gallery/#_featured--" & $i)

_IELoadWait($Obj)

EndIf

;************* ADDED **************

$oImgs = _IEImgGetCollection($Obj)

For $oImg In $oImgs

If $oImg.src = "http://penguina-mica.deviantart.com/gallery/" And $oImg.height = 0 And $oImg.width = 0 Then ; Check

for pics that are disabled. (I.E. not logged in)

GUIDelete($HidPicForm)

Return "Not logged in. Please log in via IE."

EndIf

Next

$oImgs = _IEImgGetCollection($Obj)

For $oImg In $oImgs

If $oImg.src = "http://penguina-mica.deviantart.com/gallery/" Or $oImg.height < 25 And $oImg.width < 25 Then ; Sort

out DA original pics.

$s = $s - 1

Else

$Result = StringInStr($oImg.src, ".jpg")

If Not $Result = 0 Then

$StringSplit = StringReplace($oImg.src, "http://th", "http://fc") ; Replace preview adress with real

address.

$DownloadString = StringReplace($StringSplit, "/150/i/", "/i/") ; Same ^

$Download = InetGet($DownloadString, "C:\Pics\Pic" & $s & ".jpg") ; ******** CHANGED ********

Else

$s = $s - 1

EndIf

EndIf

$s = $s + 1

;If $s >= 25 Then ExitLoop ; I can only display 24 pics per page. ; ******** CHANGED ********

Next

Next

GUIDelete($HidPicForm)

Return "Complete."

EndFunc

I have also attached my working script, in case the changes made are not clear to you.....IE Image Download Test.au3

P.S. - Just make sure the directory is created before trying to download...but I think you already knew that....

Regards,

alb19542006

Edited by alb19542006
Link to comment
Share on other sites

  • 1 year later...

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