Sign in to follow this  
Followers 0
peterchua89

Autoit randomly select photo from selection (IE)

8 posts in this topic

Hi Autoit Experts,

I have a question regarding random selection of photos from IE. I've been searching from forum & Google with no luck. The only thread I found is >Link & >Link, but both of this thread does not explain more in detail. Maybe any experts can help me out here?

Objective: To select (10) random photos from a selection in IE.

<div id="selectable_photos">
      <div class="form_line">
        <div class="heading">Shared Photos</div>
        <div class="comment">Click on photo to select / unselect from shared library.</div>
        <div class="gallery_list" data-max="10" data-per-page="20" id="shared_photos"><div class="thumb" id="photo4247949"><a data-photo="4247949" href="#"><img alt="Dsc 1063 1  thumb" src="http://dsc.propwall.com/photos/4247949/DSC_1063_1__thumb.JPG" title="Click to select / unselect photo." /></a></div><div class="thumb" id="photo4247942"><a data-photo="4247942" href="#"><img alt="Dsc 1052 1  thumb" src="http://dsc.propwall.com/photos/4247942/DSC_1052_1__thumb.JPG" title="Click to select / unselect photo." /></a></div><div class="thumb" id="photo4247931"><a data-photo="4247931" href="#"><img alt="Dsc 1062 1  thumb" src="http://dsc.propwall.com/photos/4247931/DSC_1062_1__thumb.JPG" title="Click to select / unselect photo." /></a></div><div class="thumb" id="photo4212368"><a data-photo="4212368" href="#"><img alt="Img 20141108 180532 thumb" src="http://dsc.propwall.com/photos/4212368/IMG_20141108_180532_thumb.jpg" title="Click to select / unselect photo." /></a></div><div class="thumb" id="photo4212341"><a data-photo="4212341" href="#"><img alt="Img 20141108 wa0013 thumb" src="http://dsc.propwall.com/photos/4212341/IMG-20141108-WA0013_thumb.jpg" title="Click to select / unselect photo." /></a></div><div class="thumb" id="photo4212337"><a data-photo="4212337" href="#"><img alt="Img 20141108 wa0011 thumb" src="http://dsc.propwall.com/photos/4212337/IMG-20141108-WA0011_thumb.jpg" title="Click to select / unselect photo." /></a></div><div class="thumb" id="photo4212335"><a data-photo="4212335" href="#"><img alt="Img 20141108 wa0010 thumb" src="http://dsc.propwall.com/photos/4212335/IMG-20141108-WA0010_thumb.jpg" title="Click to select / unselect photo." /></a></div><div class="thumb" id="photo4212208"><a data-photo="4212208" href="#"><img alt="Image thumb" src="http://dsc.propwall.com/photos/4212208/image_thumb.jpg" title="Click to select / unselect photo." /></a></div><div class="thumb" id="photo4212205"><a data-photo="4212205" href="#"><img alt="Image thumb" src="http://dsc.propwall.com/photos/4212205/image_thumb.jpg" title="Click to select / unselect photo." /></a></div><div class="thumb" id="photo4212200"><a data-photo="4212200" href="#"><img alt="Image thumb" src="http://dsc.propwall.com/photos/4212200/image_thumb.jpg" title="Click to select / unselect photo." /></a></div><div class="thumb" id="photo4207542"><a data-photo="4207542" href="#"><img alt="Img 20141108 wa0005 1  thumb" src="http://dsc.propwall.com/photos/4207542/IMG-20141108-WA0005_1__thumb.jpg" title="Click to select / unselect photo." /></a></div><div class="thumb" id="photo4207537"><a data-photo="4207537" href="#"><img alt="Img 20141108 wa0004 1  thumb" src="http://dsc.propwall.com/photos/4207537/IMG-20141108-WA0004_1__thumb.jpg" title="Click to select / unselect photo." /></a></div><div class="thumb" id="photo4207534"><a data-photo="4207534" href="#"><img alt="Img 20141108 wa0003 2  thumb" src="http://dsc.propwall.com/photos/4207534/IMG-20141108-WA0003_2__thumb.jpg" title="Click to select / unselect photo." /></a></div><div class="thumb" id="photo4184962"><a data-photo="4184962" href="#"><img alt="7 thumb" src="http://dsc.propwall.com/photos/4184962/7_thumb.jpg" title="Click to select / unselect photo." /></a></div><div class="thumb" id="photo4184959"><a data-photo="4184959" href="#"><img alt="6 thumb" src="http://dsc.propwall.com/photos/4184959/6_thumb.jpg" title="Click to select / unselect photo." /></a></div><div class="thumb" id="photo4184957"><a data-photo="4184957" href="#"><img alt="5 thumb" src="http://dsc.propwall.com/photos/4184957/5_thumb.jpg" title="Click to select / unselect photo." /></a></div><div class="thumb" id="photo4184954"><a data-photo="4184954" href="#"><img alt="3 thumb" src="http://dsc.propwall.com/photos/4184954/3_thumb.jpg" title="Click to select / unselect photo." /></a></div><div class="thumb" id="photo4184952"><a data-photo="4184952" href="#"><img alt="2 thumb" src="http://dsc.propwall.com/photos/4184952/2_thumb.jpg" title="Click to select / unselect photo." /></a></div><div class="thumb" id="photo4155612"><a data-photo="4155612" href="#"><img alt="Regalia 2 thumb" src="http://dsc.propwall.com/photos/4155612/Regalia_2_thumb.JPG" title="Click to select / unselect photo." /></a></div><div class="thumb" id="photo4155611"><a data-photo="4155611" href="#"><img alt="Regalia 1 thumb" src="http://dsc.propwall.com/photos/4155611/Regalia_1_thumb.JPG" title="Click to select / unselect photo." /></a></div></div>
        
            <div class="ajax_loader">
  <button class="btn btn-small btn-block" data-location="putra" data-property="regalia" data-type="shared" id="ajax_shared" name="button" type="button">Load More Photos</button>
</div>
          
      </div>
    </div>

Q: Can Autoit randomly select 10 out of those random Image links? How can we get into the links?

I have tried using _IEImgClick() and it work but only able to select the photo by its specific link, what if I dont know what is after "http://dsc.propwall.com/photos/" or I dont know what is the links? Is it still be possible?

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Yes it can. First you have to count how many images there and identify what kind they can be (jpg, gif, etc). Then put the images in a list. I would use an array. Then use autoits random function to choose randomly 10 images from the array. 1 question - Are you looking for autoit to choose 10 thumbnails or the images that the thumbnails link to?

And your link doesnt work for me.

Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi @computergroove, yeah Im looking for autoit to randomly choose 10 thumbnails from the above HTML. The links "http://dsc.propwall.com/photos/....." is actually extracted from the html. it seems to me that those image links/thumbnails that I want to select are usually start with ""http://dsc.propwall.com/photos/ "......." and so on. How can we make autoit to only look for image links that start with "http://dsc.propwall.com/photos/"?

Also the file type are usually JPG. (can autoit select links that ends with a JPG extention?)

Any clue to give me?  :

Edited by peterchua89

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I can help you write some code but I need a working website to test it on. Can you provide the web address or another one like it?

Edit - I made this for a guy on the forums that taked am html file and gets all the specific links from it and puts it into an array:

#include <array.au3>
#include <File.au3>
#include <String.au3>

Global $temp
Global $aArray[0]
$temp = FileRead(@ScriptDir & '\Syncron Solutions - User.htm');get your url and put it here
$aArray = _StringBetween($temp,'<li class="duallist-item"','">',1);Change the info in the () to the common start and end of the string
_ArrayDisplay($aArray)
Edited by computergroove
1 person likes this

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

Try this.

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

Local $iNumOfRandImgsRet = 8

;Get All Image links into an array.
; Either
Local $oIE = _IECreate("http://www.autoitscript.com/", 0, 1) ; <--- Last "1" parameter shows browser window.
; Or
#cs
    Local $oIE = _IECreate("about:blank", 0, 0) ; <--- Last "0" parameter hides browser window.
    _IEDocWriteHTML($oIE, FileRead("HtmTextFromPost1.htm")) ; Text from Post#1 saved to "HtmTextFromPost1.htm" file in same folder as this script, or, use full path name.
    _IEAction($oIE, "refresh")
#ce

Local $oImgs = _IEImgGetCollection($oIE)
Local $iNumImg = @extended
Local $aImgArray[$iNumImg] ; Array to hold all image links
Local $iCount = -1
For $oImg In $oImgs
    $iCount += 1
    $aImgArray[$iCount] = $oImg.src
Next
_IEQuit($oIE)

; Get a unique array of a number of random links.
_ArrayUnique($aImgArray) ; Ensure there are no duplicate image links.
_ArrayDisplay($aImgArray, "All " & $iNumImg & " Images Found")
_ArrayShuffle($aImgArray) ; Randomize array
_ArrayDelete($aImgArray, Execute('"' & $iNumOfRandImgsRet & '-' & (UBound($aImgArray) - 1) & '"'))
_ArrayDisplay($aImgArray, $iNumOfRandImgsRet & " Random Images")

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

@Malkey, that script works great!!  :thumbsup:  However if I may ask again because I really dont understand how arrays work. The links displayed out, can I put a conditional filter whereby the 8 Randoms links displayed must contains "http://dsc.propwall.com/photos/....."? if yes which array function I should be using?

Sorry Im kind of new here.. really did my best trying to understand array here..  :ranting:

Edited by peterchua89

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

This loop is adding things to your array, i would put your condition here.   

For $oImg In $oImgs  

  $iCount += 1  

If this item meets this condition then $aImgArray[$iCount] = $oImg.src

Next

 

And checking to see if a substring exists in a string, is a string function.

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Arrays are storage bins.  Sort of like an egg carton.

If I bought a dozen eggs, there would be 12 slots to hold my eggs.

In autoit, our slots are designed with brackets, and the number of slots.

[12] as an example

so...

$a_array[12] holds 12 slots I can access data from, starting with index 0 and ending with 11

eg.

$a_array[0] = "egg 1"

$a_array[1] = "egg 2"

etc...

$a_array[11] = "egg 12"

This may help you much better, but I understood it myself when I thought of the egg container.

https://www.autoitscript.com/wiki/Arrays


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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