Jump to content

Downloading Pictures


Recommended Posts

How would i go about automatically downloading all the images on a certain site?

i've started this inetget example of what i want, but its not working... any ideas where i should go from here? how what i'm doing wrong?

it works with this site (only one i've tested) "http://www.autoitscript.com/"

whats not working:"http://www.autoitscript.com/forum/"

why?

:S what can i do?

#include <INet.au3>
#include <String.au3>
Do
    $choice = MsgBox (4,'welcome','Would you like to download?')
    If $choice = 6 Then
        $Website = InputBox ('Website','Pick A Website To Scavenge The Downloadable Content.')
        If Not @error Then
        ;~  ConsoleWrite (GetFileName ($Website) & @CRLF)
            ProgressOn ('downloading','starting...')
            $Source = _INetGetSource($Website)
            ;images
            $array = _StringBetween ($Source,' src', '>')
            If IsArray ($array) Then
                ConsoleWrite ($Website & ' has images:' & UBound ($array) & @CRLF)
                For $n = 0 To UBound ($array)-1
                    $patharray = _StringBetween ($array[$n],'="','" ')
                    If IsArray ($patharray) Then
                        $percent = Round (100*($n/UBound ($array)))
                        ProgressSet ($percent,$percent,'Downloading Content...')
                        GetFile ($Website,$patharray[0])
                    EndIf
                Next
            EndIf
            ProgressOff ()
        EndIf
    EndIf
Until $choice = 7





Func GetSiteName ($Website)
    Local $array = StringSplit ($Website,'.')
    Return $array[2]
EndFunc





Func GetFileName ($FilePath)
    Local $tpath = $FilePath
    Do
        If StringInStr ($tpath,'\') Or StringInStr ($tpath,'/') Then
            $tpath = StringTrimLeft ($tpath,1)
        Else
            Return $tpath
        EndIf
    Until False
EndFunc





Func GetFile ($Website,$FilePath)
    Local $FileName = GetFileName ($FilePath)
    Local $SiteName = GetSiteName ($Website)
    Local $Dir = @DesktopDir & '\' & $SiteName & '\'
    Local $FullPath
    If StringLeft ($FilePath,1) == '/' Then
        Local $FullPath = $Website & $FilePath
    Else
        Local $FullPath = $Website & '/' & $FilePath
    EndIf
    If Not FileExists ($Dir) Then
        DirCreate ($Dir)
    EndIf
    Local $hDownload =  InetGet($FullPath, $Dir & $FileName,16 + 2 + 1)
    InetClose($hDownload)
EndFunc
Link to comment
Share on other sites

Example from helpfile

; *******************************************************
; Example 2 - Create browser at AutoIt homepage, get Img collection
;               and display src URL for each
; *******************************************************

#include <IE.au3>
$oIE = _IECreate ("http://www.autoitscript.com/")
$oImgs = _IEImgGetCollection($oIE)
$iNumImg = @extended
MsgBox(0, "Img Info", "There are " & $iNumImg & " images on the page")
For $oImg In $oImgs
    MsgBox(0, "Img Info", "src=" & $oImg.src)
Next
Edited by Zedna
Link to comment
Share on other sites

WOW! jeez thanks for that, i never knew that was even in the helpfile!

However, i would like to do it in the background... instead of opening a webpage, just get the source of the page and get the images from that source directly... im kinda doing it to monitor our webpages image library remotely, and i don't want the school soccer website popping up every time i want to see if there is an extra picture from a

tournament. :\

is this even possible with InetGet? if not ill be glad to use the example you gave me Zedna!

Link to comment
Share on other sites

or set the visible parameter to 0 on IECreate.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

oooh! okay. i did that, and it works beautifully!!!

however, now... my inetgetinfo () functions aren't working at all... whats wrong with this? inetget works, like it downloads the images and places them in their own folder, but when i check for the percentage its returning this:

InetGetInfo($hDownload, 0) returns 0

InetGetInfo($hDownload, 1) returns 0

InetGetInfo($hDownload, 2) returns false

InetGetInfo($hDownload, 3) returns false

InetGetInfo($hDownload, 4) returns 0

InetGetInfo($hDownload, 5) returns 0

:)

Link to comment
Share on other sites

Those small pics all download to quickly. For a large amount of small items I would just do a percentage or amount of the whole, or just a running tally of how much has been copied (as is the example below).

#include <IE.au3>

Global $Totalbytes

$oIE = _IECreate ("http://www.foxnews.com/" , 0 , 0)
$oImgs = _IEImgGetCollection($oIE)
$iNumImg = @extended

_getstuff()

tooltip ("completed " & $iNumImg & "  Images with a total size of " & $Totalbytes / 1000 / 1000 & "MB." , 0 , 0)

sleep (3000)

exit

Func _getstuff()

    $i = 1

For $oImg In $oImgs
    $Size = inetgetsize($oImg.src , 1)
    $ImGet = inetget($oImg.src , "C:\temppics\pic" & $i & ".jpg" , 1 , 1)
    $Totalbytes += $Size
    $i += 1

        tooltip ("  Item #" & $i & " downloaded " & $Totalbytes / 1000 / 1000 & "MB." , 0 , 0)


    Next

EndFunc
Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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