Sign in to follow this  
Followers 0
DarkWinds

Saving single image on webpage to folder

4 posts in this topic

I'm trying to have a script click next then save a certain image on a webpage then click next again and so on, looping it.

I put together this from 2 different examples and modified it a tad. My problem is i don't understand why it won't loop. It stops after the first one. Even if i reput the code below it still terminates itself.

The script actually downloads all the images on the page but i couldn't figure out how to download the image i wanted. I wanted it to download the image by getting close to the URL of the image i wanted, As far as i know the URL to the image always ends with "Selected.jpg" so i tried to get it to download any image with that at the end so it would always download the one i wanted but i couldn't make it work.

Any help would be much appreciated.

#include <IE.au3>

$sImgDir = "c:\foo\"; Please make certain this folder already exists (silent failure if not)
$sWebPage = "http://www.crispygamer.com/comics/experiencepoints/experiencepoints-2008-10-25.aspx"; webpage with images

$oIE = _IECreate($sWebPage)
$oIMGs = _IEImgGetCollection($oIE)
While 1
; Loop through all IMG tags and save file to local directory using INetGet
For $oIMG In $oIMGs
    $sImgUrl = $oIMG.src
    $sImgFileName = $oIMG.nameProp
    InetGet($sImgUrl, $sImgDir & $sImgFileName)
Next

$sMyString = "Next"
$oLinks = _IELinkGetCollection($oIE)
For $oLink In $oLinks
    $sLinkText = _IEPropertyGet($oLink, "innerText")
    If StringInStr($sLinkText, $sMyString) Then
        _IEAction($oLink, "click")
    EndIf
Next
WEnd

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#include <ie.au3>


$start = 0
$searchWord = "cats"
$searchWord = StringReplace($searchWord, " ", "+") ; replace all spaces with "+"
$url = "http://www.google.co.uk/images?q=" & $searchWord & "&um=1&hl=en&biw=1280&bih=518&tbs=isch:1&ei=qiLsTJaiDoGAhQei1qHNDA&sa=N&start=" & $start & "&ndsp=20"
$oIE =  _IECreate($url)



while $start <= 960
    $images = _IEImgGetCollection($oIE)
    For $image in $images
        $split = StringSplit($image.src, "/")
        $filename = $split[$split[0]]
        ConsoleWrite($filename& @CRLF)
        InetGet($image.src, "C:\tempimg\" & $filename)
    Next

    $start = $start +20
    ConsoleWrite($start & "----------------" & @CRLF);
    $url = "http://www.google.co.uk/images?q=" & $searchWord & "&um=1&hl=en&biw=1280&bih=518&tbs=isch:1&ei=qiLsTJaiDoGAhQei1qHNDA&sa=N&start=" & $start & "&ndsp=20"
    _IENavigate($oIE, $url)
    _IELoadWait($oIE)
    Sleep(3000)

This is a random script i put together while bored. Searches for "cats" or whatever you change $searchWord too on google, then loops through each page downloading images.

This will block you eventually, google detects random amounts of traffic from your IP and blocks you for like 30seconds or so.

Edited by Steveiwonder

They call me MrRegExpMan

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Any help would be much appreciated.

It works better like this ! Posted Image

#include <IE.au3>

$sImgDir = "c:\foo\"; Please make certain this folder already exists (silent failure if not)
DirCreate ( $sImgDir )
$sWebPage = "http://www.crispygamer.com/comics/experiencepoints/experiencepoints-2008-10-25.aspx"; webpage with images

$oIE = _IECreate($sWebPage)

While 1
    $oIMGs = _IEImgGetCollection($oIE)
    ; Loop through all IMG tags and save file to local directory using INetGet
    For $oIMG In $oIMGs
        $sImgUrl = $oIMG.src
        $sImgFileName = $oIMG.nameProp
        ConsoleWrite ( "$sImgFileName : " & $sImgFileName & @Crlf )
        InetGet($sImgUrl, $sImgDir & $sImgFileName)
    Next
    $sMyString = "Next"
    $oLinks = _IELinkGetCollection($oIE)
    For $oLink In $oLinks
        $sLinkText = _IEPropertyGet($oLink, "innerText")
        If StringInStr($sLinkText, $sMyString) Then
            _IEAction($oLink, "click")
            _IELoadWait ( $oIE )
        EndIf
    Next
WEnd

Some images filenames have no extension, they are not downloaded...

Edited by wakillon

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

Share this post


Link to post
Share on other sites

Thanks for the help guy's, I appreciated it a lot. There's still alot i need to learn :P

Worked perfectly Wakillon thanks :x ... Real men hug right?

Share this post


Link to post
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
Sign in to follow this  
Followers 0