Jump to content

picture downloader


tsue
 Share

Recommended Posts

Hi tsue,

with AutoIT you can use the functions InetGet, InetGetSize, InetGetInfo and so on. So all you need to do is parse the HTML code that you download.

User InetGet to download the HTML sourcecode, extract the "<img src='123.jpg'>" tags and hand them again over to InetGet.

Regards,

Hannes

:x

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

hello, im trying to make a program that downloads webpictures, but i have never used a program that searches in the internet

do you know where can i star like basic conection from a program to the internet

A program that searches in the internet ?

I have made some months ago a search pic function by google, try it ! Posted Image

#include <String.au3>
#include <Array.au3>

Global $_OutputDir = @DesktopDir & '\Pics'
DirCreate ( $_OutputDir )
$_Search = _GetImagesByGoogleSearch ( 'Lady Gaga' )
;_ArrayDisplay ( $_Search )

For $_I = 1 To UBound ( $_Search ) -1
    InetGet ( $_Search[$_I], $_OutputDir & '\' & _GetFullNameByUrl ( $_Search[$_I] ) , 1, 0 )
Next
ShellExecute ( $_OutputDir )
Exit

Func _GetImagesByGoogleSearch ( $_ItemSearch )
    $_PicSearchUrl = 'http://www.google.co.nz/images?hl=en&q=' & StringReplace ( StringReplace _
    ( StringReplace ( $_ItemSearch, '-', '' ), ' ', '+' ), '++', '+' ) & '&btnG=Search'
    $_SourceCode = _GetSourceCode ( $_PicSearchUrl )
    $_StringInstrArrayOfLine = _StringInstrArrayOfLine ( $_SourceCode, 'img src=' )
    $_UrlImageArray = _StringBetweenArrayByStringInstrArray ( $_SourceCode, $_StringInstrArrayOfLine, 'img src=', ' ' )
    If _IsArrayEmpty ( $_UrlImageArray ) Then 
        Return ''
    Else    
        Return $_UrlImageArray
    EndIf
EndFunc ;==> _GetImagesByGoogleSearch ( )

Func _GetSourceCode ( $_Url )
    $_InetRead = InetRead ( $_Url )
    If Not @Error Then
        $_BinaryToString = BinaryToString ( $_InetRead )
        If Not @Error Then Return $_BinaryToString
    EndIf   
EndFunc ;==> _GetSourceCode ( )

Func _StringBetweenArrayByStringInstrArray ( $_String, $_StringInStrArray, $_Start, $_End )
    Dim $_ArrayAdd[1]
    For $_I = 1 To UBound ( $_StringInStrArray ) -1
        $_StringRight = StringRight ( $_String, StringLen ( $_String ) - $_StringInStrArray[$_I] +1 )
        Local $_StringBetween = _StringBetween ( $_StringRight, $_Start, $_End )
        If Not @error Then _ArrayAdd ( $_ArrayAdd, $_StringBetween[0] )
    Next
    Return $_ArrayAdd
EndFunc ;==> _StringBetweenArrayByStringInstrArray ( )

Func _StringInstrArrayOfLine( $_String, $_StringToFind )
    Dim $_ArrayAdd[1]
    For $_I = 1 To StringLen ( $_String )
        $_StringInStr = StringInStr ( $_String, $_StringToFind, 0, $_I )
        If $_StringInStr = 0 Then 
            $_ArrayAdd[0] = UBound ( $_ArrayAdd ) -1
            Return $_ArrayAdd
        Else
            _ArrayAdd ( $_ArrayAdd, $_StringInStr )
        EndIf
    Next
EndFunc ;==> _StringInstrArrayOfLine( )

Func _IsArrayEmpty ( $_EmptyArray )
    Local $_V = UBound ( $_EmptyArray ) -1, $_P 
    If $_V = 0 Then Return True
    For $_F = 1 To $_V      
        If $_EmptyArray[$_F] = '' Then $_P = $_P + 1
    Next
    If $_P = $_V Then 
        Return True
    Else
        Return False
    EndIf
EndFunc ;==> _IsArrayEmpty ( )

Func _GetFullNameByUrl ( $_FileUrl )
    $_FileName = StringSplit ( $_FileUrl, '/' )
    If Not @error Then 
        Return $_FileName[$_FileName[0]]
    Else
        Return 0
    EndIf
EndFunc ;==> _GetFullNameByUrl ( )

AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

A program that searches in the internet ?

I have made some months ago a search pic function by google, try it ! Posted Image

#include <String.au3>
#include <Array.au3>

Global $_OutputDir = @DesktopDir & '\Pics'
DirCreate ( $_OutputDir )
$_Search = _GetImagesByGoogleSearch ( 'Lady Gaga' )
;_ArrayDisplay ( $_Search )

For $_I = 1 To UBound ( $_Search ) -1
    InetGet ( $_Search[$_I], $_OutputDir & '\' & _GetFullNameByUrl ( $_Search[$_I] ) , 1, 0 )
Next
ShellExecute ( $_OutputDir )
Exit

Func _GetImagesByGoogleSearch ( $_ItemSearch )
    $_PicSearchUrl = 'http://www.google.co.nz/images?hl=en&q=' & StringReplace ( StringReplace _
    ( StringReplace ( $_ItemSearch, '-', '' ), ' ', '+' ), '++', '+' ) & '&btnG=Search'
    $_SourceCode = _GetSourceCode ( $_PicSearchUrl )
    $_StringInstrArrayOfLine = _StringInstrArrayOfLine ( $_SourceCode, 'img src=' )
    $_UrlImageArray = _StringBetweenArrayByStringInstrArray ( $_SourceCode, $_StringInstrArrayOfLine, 'img src=', ' ' )
    If _IsArrayEmpty ( $_UrlImageArray ) Then 
        Return ''
    Else    
        Return $_UrlImageArray
    EndIf
EndFunc ;==> _GetImagesByGoogleSearch ( )

Func _GetSourceCode ( $_Url )
    $_InetRead = InetRead ( $_Url )
    If Not @Error Then
        $_BinaryToString = BinaryToString ( $_InetRead )
        If Not @Error Then Return $_BinaryToString
    EndIf   
EndFunc ;==> _GetSourceCode ( )

Func _StringBetweenArrayByStringInstrArray ( $_String, $_StringInStrArray, $_Start, $_End )
    Dim $_ArrayAdd[1]
    For $_I = 1 To UBound ( $_StringInStrArray ) -1
        $_StringRight = StringRight ( $_String, StringLen ( $_String ) - $_StringInStrArray[$_I] +1 )
        Local $_StringBetween = _StringBetween ( $_StringRight, $_Start, $_End )
        If Not @error Then _ArrayAdd ( $_ArrayAdd, $_StringBetween[0] )
    Next
    Return $_ArrayAdd
EndFunc ;==> _StringBetweenArrayByStringInstrArray ( )

Func _StringInstrArrayOfLine( $_String, $_StringToFind )
    Dim $_ArrayAdd[1]
    For $_I = 1 To StringLen ( $_String )
        $_StringInStr = StringInStr ( $_String, $_StringToFind, 0, $_I )
        If $_StringInStr = 0 Then 
            $_ArrayAdd[0] = UBound ( $_ArrayAdd ) -1
            Return $_ArrayAdd
        Else
            _ArrayAdd ( $_ArrayAdd, $_StringInStr )
        EndIf
    Next
EndFunc ;==> _StringInstrArrayOfLine( )

Func _IsArrayEmpty ( $_EmptyArray )
    Local $_V = UBound ( $_EmptyArray ) -1, $_P 
    If $_V = 0 Then Return True
    For $_F = 1 To $_V      
        If $_EmptyArray[$_F] = '' Then $_P = $_P + 1
    Next
    If $_P = $_V Then 
        Return True
    Else
        Return False
    EndIf
EndFunc ;==> _IsArrayEmpty ( )

Func _GetFullNameByUrl ( $_FileUrl )
    $_FileName = StringSplit ( $_FileUrl, '/' )
    If Not @error Then 
        Return $_FileName[$_FileName[0]]
    Else
        Return 0
    EndIf
EndFunc ;==> _GetFullNameByUrl ( )

hello, im still not very used to inet get, im trying to make a download in paralel with out having to close inetget for each image downloaded

Local $hDownload = InetGet("http://www.rayearth2.freehost.pl/images/magic_knight_rayearth-chibi-cephiro-master_mage_yil_clef02.jpg", "clef.jpg", 1, 0)
Local $hDownload2 = InetGet("http://www.rayearth2.freehost.pl/images/magic_knight_rayearth-chibi-cephiro-master_mage_yil_clef03.jpg", "clef2.jpg", 1, 0)
Local $hDownload3 = InetGet("http://www.rayearth2.freehost.pl/images/magic_knight_rayearth-chibi-cephiro-master_mage_yil_clef04.jpg", "clef3.jpg", 1, 0)
Local $hDownload4 = InetGet("http://www.rayearth2.freehost.pl/images/magic_knight_rayearth-chibi-cephiro-master_mage_yil_clef05.jpg", "clef4.jpg", 1, 0)
Do
    Sleep(250)
Until InetGetInfo($hDownload, 2) and InetGetInfo($hDownload2, 2) and InetGetInfo($hDownload3, 2) and InetGetInfo($hDownload4, 2)    ; Check if the download is complete.
Local $nBytes = InetGetInfo($hDownload, 0)
Local $nBytes2 = InetGetInfo($hDownload2, 0)
Local $nBytes3 = InetGetInfo($hDownload3, 0)
Local $nBytes4 = InetGetInfo($hDownload4, 0)

InetClose($hDownload)   ; Close the handle to release resourcs.
InetClose($hDownload2)
InetClose($hDownload3)
InetClose($hDownload4)
MsgBox(0, "", "Bytes read: " & $nBytes)
Edited by tsue
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...