Jump to content

Autoit Script quit without any error using InetGet Function


Recommended Posts

Hey

I'm trying to use InetGet function to download multiple images from a website, some pages having three images, some pages having 4 images some of them having more...

I wrote belong codes to work with autoit and having issues when autoit find not matching url available then autoit just script stopped without any error and I just want to same all the avaialble images on the website if links are not more left then script should moves on but script just stopped...

Here is complete scenerio

I've so many webpages with random number of images are hosting on those pages, in below code, InetGet able to download first three files easily and when it reaches to 4th link that is missing on the webpage that's why script stopped just but I want autoit to download only those images those are links are available and rest of files needs to be skipped automatically for this page if on the next page 4th link of image avaiable then autoit script needs to download 4th one also.

Furthermore, please help me to download files with it's original names instead of whatever name I want to same them like in InetGet I've to give some name to the file that I'm willind to download instead of original name that is available online.

Please Help me.

Here i my code;

$File6 = @ScriptDir & "\images_source.txt"
$txt6 = FileRead($File6)
$target_source7 = _StringBetween($txt6, 'src="', '"')
if Not @error Then
InetGet ( $target_source7[0], @ScriptDir & '\Description\Image1.jpg'); 1st image download coz link is available 
InetGet ( $target_source7[1], @ScriptDir & '\Description\Image2.jpg'); 2nd image download coz link is available
InetGet ( $target_source7[2], @ScriptDir & '\Description\Image3.jpg'); 3rd image download coz link is available
InetGet ( $target_source7[3], @ScriptDir & '\Description\Image4.jpg'); 4th image not able to download coz link is not available and script just stopped
EndIf

 

Link to comment
Share on other sites

Have you tried:

Do you have a copy of images_source.txt that we can use to get the original file names?

$File6 = @ScriptDir & "\images_source.txt"
$txt6 = FileRead($File6)
$target_source7 = _StringBetween($txt6, 'src="', '"')
if Not @error Then
InetGet ( $target_source7[0], @ScriptDir & '\Description\Image1.jpg', 0, 1); 1st image download coz link is available 
InetGet ( $target_source7[1], @ScriptDir & '\Description\Image2.jpg', 0, 1); 2nd image download coz link is available
InetGet ( $target_source7[2], @ScriptDir & '\Description\Image3.jpg', 0, 1); 3rd image download coz link is available
InetGet ( $target_source7[3], @ScriptDir & '\Description\Image4.jpg', 0, 1); 4th image not able to download coz link is not available and script just stopped
EndIf

 

Edited by Subz
Link to comment
Share on other sites

Hey Subz,

Basically I saved website source first into text file that is "images_source.txt" then use the codes next I quoted above but every URL having different number of image-URLs that's why when I removed the code of InetGet of 4th line it works for me on current URL's source code but on next pages I've more image URLs that's why I have to skip rest of images coz If I remove 4th line my script can only download first 3 files and rest of them I've to skip but I want to download all the images that a source code contains. ....So please guide me how can I pass the loop or something similar that can avoid showing me problem what I'm facing now...

Link to comment
Share on other sites

Try this code:

#include <Array.au3>
#include <IE.au3>
#include <InetConstants.au3>

Local $oIE = _IECreate("http://www.rodsbyreid.co.nz/gallery.html")
Local $oImages = _IEImgGetCollection($oIE)
Local $aImages[0][2]
Local $hImage, $sImage, $sGallery = @ScriptDir & '\Description\'
For $oImage In $oImages
    $sImage = $sGallery & Execute("'" & StringRegexpReplace(StringTrimLeft($oImage.src, StringInStr($oImage.src, "/", 0, -1)), "%([0-9a-fA-F]{2})", "'& Chr(0x$1) &'") & "'")
    _ArrayAdd($aImages, $oImage.src & "|" & $sImage)
Next
_ArrayAdd($aImages, "http://www.rodsbyreid.co.nz/noimageexists.jpg|" & $sGallery & "\noimageexists.jpg")
_ArrayDisplay($aImages)
If FileExists($sGallery) = 0 Then DirCreate($sGallery)
For $i = 0 To UBound($aImages) - 1
    If FileExists($aImages[$i][1]) = 0 Then
        $hImage = InetGet($aImages[$i][0], $aImages[$i][1], $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)
        Do
            Sleep(250)
        Until InetGetInfo($hImage, $INET_DOWNLOADCOMPLETE) Or InetGetInfo($hImage, $INET_DOWNLOADERROR )
    EndIf
Next

_IEQuit($oIE)
Exit

 

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

×
×
  • Create New...