How to loop on a LIST variable
here's another quick tutorial for LoliScript.
Let's say you have a variable called
LIST123and you want to perform some action on all its elements.
Sometimes, like in the case of the
FUNCTIONblock, you can type
<LIST123[*]>in the input field and the block will be executed on all the elements of the list at the same time.
Other times you might want to perform multiple requests after scraping links e.g. after a google search.
This is how you can set up a loop in a very ASM-like fashion to get what you want:
UTILITY List "LIST123" Length -> VAR "LEN" SET VAR "INDEX" "0" WHILE "<INDEX>" LessThan "<LEN>" ## Do something with the list element like this: PRINT "<LIST123[<INDEX>]>" FUNCTION Compute "<INDEX>+1" -> VAR "INDEX" ENDWHILE
jaygit last edited by jaygit
I am only able to print last username and password but not able to print all username and passwords. have a look below:
<--- Executing Block get_Username --->
Parsed variable | Name: Username | Value: henryhk
<--- Executing Block get_pass --->
Parsed variable | Name: Password | Value: krlynch8790
<--- Executing Block FUNCTION --->
Executed function Compute on input 4+1 with outcome 5
Parsed variable | Name: INDEX | Value: 5
Jumping to line 49
Jumping to line 69
===== DEBUGGER ENDED AFTER 32.953125 SECOND(S) WITH STATUS: SUCCESS =====
I USED FOLLOWING :
##can delete the two lines below when it is certain the capture is working as intended
FUNCTION Compute "<INDEX>+1" -> VAR "INDEX"
You are using single variables, not lists. Please check my example again, I am looping on a LIST variable!
jaygit last edited by
After looping on a LIST variable, the block executed on all the elements of the list at the same time. Now I want to parse let us say "Username" and "password" from each <sources> of elements executed in the list so how to do it?
Ah ok I get it so you want to do
START LOOP MAKE REQUEST (AND GET SOURCE) PARSE USERNAME AND PASSWORD END LOOP
An easy way would be creating two list variables (USERNAMES and PASSWORDS) and adding elements to it
This is the pseudocode now
CREATE LIST USERNAMES CREATE LIST PASSWORDS BEGIN LOOP MAKE REQUEST (AND GET SOURCE) PARSE USERNAME ADD USERNAME TO USERNAMES PARSE PASSWORD ADD PASSWORD TO PASSWORDS END LOOP
To create lists you can use
UTILITY List "" Create -> VAR "USERNAMES" UTILITY List "" Create -> VAR "PASSWORDS"
To add the elements you can do:
UTILITY List "USERNAMES" Add "<Username>" "-1" -> VAR "USERNAMES" UTILITY List "PASSWORDS" Add "<Password>" "-1" -> VAR "PASSWORDS"
-1is used to add them to the end of the list.
I hope the LS syntax is correct because I didn't test it but you get the general idea.
jaygit last edited by
Thanks a lot Ruri. u r simply master.
let's say a parse block parsed a list of id, now i want to perform a request for every single item in that this, is there any way i can do this?
@Ruri please help me out.
@leecher101 that's exactly what my code is for. When i write "do something with the list element" it means instead of just printing it you can make a request with it, using
<LIST123[<INDEX>]>as the URL.
@Ruri thanks worked
Micro last edited by
Is there a way to do this multithreaded ?
In example, my scraped list contains 50 Id's and I want to loop these with multiple threads to speed it up.
Uhm not really no, but it might be a good idea for a new command ^_^