DarkWinds Posted December 20, 2010 Share Posted December 20, 2010 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 Link to comment Share on other sites More sharing options...
Steveiwonder Posted December 20, 2010 Share Posted December 20, 2010 (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 December 20, 2010 by Steveiwonder They call me MrRegExpMan Link to comment Share on other sites More sharing options...
wakillon Posted December 20, 2010 Share Posted December 20, 2010 (edited) Any help would be much appreciated. It works better like this ! #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 December 20, 2010 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
DarkWinds Posted December 20, 2010 Author Share Posted December 20, 2010 Thanks for the help guy's, I appreciated it a lot. There's still alot i need to learn Worked perfectly Wakillon thanks ... Real men hug right? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now