This time I would be showing how to download a maximum of upto 100 images appearing in the search result. This thing is pretty useful to people who regularly download wallpapers. Instead of selecting and downloading images they can actually download the images first and then delete unwanted images saving time required to select these. So as usual here is a working video ....
And here's the code explained in comments of code
;By this you will be able to download upto a max of 100 images from the google search results
;libraries....
#include <WinAPI.au3>
#include <IE.au3>
#include <GUIConstants.au3>
#include <String.au3>
;Gui to give input
$Window = GUICreate("Google Image Search", 381, 43, 193, 115)
$Label = GUICtrlCreateLabel("Search:", 8, 8, 41, 17)
$Input = GUICtrlCreateInput("", 56, 8, 217, 21)
$Go = GUICtrlCreateButton("Go!", 280, 8, 89, 25, 0)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Go
Global $sinput = GUICtrlRead($Input)
ExitLoop
EndSwitch
WEnd
;Creating destination folder
If Not FileExists("E:\imagedwnlder\" & $sinput) Then DirCreate("E:\imagedwnlder\" & $sinput)
;Url to go to..
;here this url eith "iszw:1366,iszh:768" limits the images to only with sizes 1366x768
;You can easily change this to your required size
$surl = "https://www.google.co.in/search?q=" & $sinput &"&newwindow=1&site=imghp&tbm=isch&tbs=isz:ex,iszw:1366,iszh:768"
;Opening IE and navigating to required page........
;here by making 1 in the third argument as 0 you can make the loading of page invisible
$oIE = _IECreate($surl,0,1)
;Getting the source from required page..
;This could have also be done with _INetGetSource but the links of images required would not have been loaded to the source
$sSource = _IEBodyReadHTML($oIE)
;quitting IE
_IEQuit($oIE)
;getting url and downloading the required image to specified folder
$aurl = _StringBetween($sSource, 'href="http://www.google.co.in/imgres?', '&imgrefurl=')
$nf = UBound($aurl)
MsgBox(0,"",$nf)
For $k = 0 To $nf-1
$aurl[$k] = StringReplace($aurl[$k], ".jpg", ".jpg1")
$spl = StringSplit($aurl[$k],".jpg",1)
$aurl[$k] = StringReplace($aurl[$k], ".jpg1", ".jpg")
$aurl[$k] = "http" & $aurl[$k]
$ub = UBound($spl)
$dwnld = "E:\imagedwnlder\" & $sinput & "\dwnld" & $k & ".jpg"
If ($ub==3) Then
If ($spl[2]=="1") Then
ConsoleWrite($aurl[$k] & @CRLF)
InetGet($aurl[$k],$dwnld,0,1)
EndIf
EndIf
Next
While(1)
Sleep(5000)
WEnd
;libraries....
#include <WinAPI.au3>
#include <IE.au3>
#include <GUIConstants.au3>
#include <String.au3>
;Gui to give input
$Window = GUICreate("Google Image Search", 381, 43, 193, 115)
$Label = GUICtrlCreateLabel("Search:", 8, 8, 41, 17)
$Input = GUICtrlCreateInput("", 56, 8, 217, 21)
$Go = GUICtrlCreateButton("Go!", 280, 8, 89, 25, 0)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Go
Global $sinput = GUICtrlRead($Input)
ExitLoop
EndSwitch
WEnd
;Creating destination folder
If Not FileExists("E:\imagedwnlder\" & $sinput) Then DirCreate("E:\imagedwnlder\" & $sinput)
;Url to go to..
;here this url eith "iszw:1366,iszh:768" limits the images to only with sizes 1366x768
;You can easily change this to your required size
$surl = "https://www.google.co.in/search?q=" & $sinput &"&newwindow=1&site=imghp&tbm=isch&tbs=isz:ex,iszw:1366,iszh:768"
;Opening IE and navigating to required page........
;here by making 1 in the third argument as 0 you can make the loading of page invisible
$oIE = _IECreate($surl,0,1)
;Getting the source from required page..
;This could have also be done with _INetGetSource but the links of images required would not have been loaded to the source
$sSource = _IEBodyReadHTML($oIE)
;quitting IE
_IEQuit($oIE)
;getting url and downloading the required image to specified folder
$aurl = _StringBetween($sSource, 'href="http://www.google.co.in/imgres?', '&imgrefurl=')
$nf = UBound($aurl)
MsgBox(0,"",$nf)
For $k = 0 To $nf-1
$aurl[$k] = StringReplace($aurl[$k], ".jpg", ".jpg1")
$spl = StringSplit($aurl[$k],".jpg",1)
$aurl[$k] = StringReplace($aurl[$k], ".jpg1", ".jpg")
$aurl[$k] = "http" & $aurl[$k]
$ub = UBound($spl)
$dwnld = "E:\imagedwnlder\" & $sinput & "\dwnld" & $k & ".jpg"
If ($ub==3) Then
If ($spl[2]=="1") Then
ConsoleWrite($aurl[$k] & @CRLF)
InetGet($aurl[$k],$dwnld,0,1)
EndIf
EndIf
Next
While(1)
Sleep(5000)
WEnd
You can also download source from here
0 comments:
Post a Comment