a2515125 wrote:i prefer to use the 1st script that is much more simple to me to understand BUT really have no idea how to turn string "z" into number.
I would very appreciate if you can show me .........
I also try to use my own var but it seems I do not get it
if I dont set SET !LOOP -999 instead of SET !VARLOOP -999
the script would not loop.....
PROMPT {{!VARLOOP}} shows undefined but I already give !VARLOOP 1000
it should debug it as 1000 for first prompt and as 1 for second prompt isn't it ?
Still this code below fails
Code: Select all
SET !REPLAYSPEED FAST
SET !EXTRACT_TEST_POPUP NO
SET !ERRORIGNORE YES
SET !TIMEOUT_PAGE 3
SET !TIMEOUT_STEP 0
SET !LOOP -999
SET !VARLOOP 1000
PROMPT {{!VARLOOP}}
ADD !VARLOOP {{!LOOP}}
PROMPT {{!VARLOOP}}
'extract url'
WAIT SECONDS=0.02
'set loop to scrape'
FILTER TYPE=IMAGES STATUS=ON
SET !VAR1 EVAL("var z=\"{{!VARLOOP}}\";z = (z % 40);if(z == 0){ z = 40};z=z++;")
TAG POS={{!VAR1}} TYPE=H4 ATTR=CLASS:*-i
TAG POS={{!VAR1}} TYPE=dl ATTR=CLASS:* EXTRACT=htm
SET !VAR2 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split('<dd>');y= x[1].split('</dd>'),z=y[0]; z;")
ADD Temp_Extract {{!VAR2}}
SET !EXTRACT {{!VAR2}}
TAG POS={{!VAR1}} TYPE=H4 ATTR=CLASS:*-l EXTRACT=TXT
TAG POS={{!VAR1}} TYPE=TIME ATTR=CLASS:*-r<SP>*-w EXTRACT=TXT
TAG POS={{!VAR1}} TYPE=A ATTR=CLASS:*-g<SP>media EXTRACT=HREF
Oh...!, very good...!, you are "finally" using 'PROMPT' to follow and debug your Vars...!
Possible Explanation(s) why your Script is (still) not working is that I am not sure if you can use the '!' for User Defined Vars, this is "normally" reserved for Built-in Vars, the 'PROMPT' must give you the Answer anyway... And hum, even if it works, it's "Good Practice" to keep the '!' only for Built-in Vars anyway, your Script is then easier to "follow" for yourself and other Users that might get "confused", thinking... "Oh...!, I don't know this Command, maybe it's new in Version X..."
Your 'EVAL()' was working with the raw/Built-in '!LOOP' Var for which iMacros already "knew" for sure it's always a Number...! But when using User Defined Vars, iMacros doesn't "know" if your Var is "supposed to be" a Number or a String, I think for '!VARn' Vars it makes an Attempt to "detect" and threat the Content as Number or String, but => always String in case of "Doubt", and I wouldn't be surprised if User Defined Vars are always treated as a String, especially inside 'EVAL()'...
=> Then you would need to make sure that your 'z' is converted to a Number like I already mentioned several times...
Your "... BUT really have no idea how to turn string "z" into number." is a bit "useless", ah-ah...!
Simply start typing "
convert str[ing to number javascript]" in Google and you already have the Answer(s)...! Not very complicated I would think...!
=> 'parseInt()' + 'parseFloat()' + 'Number()'...
Hum, even if I remember "trying" once the 'Number()' Method (on iMacros for FF, probably v8.8.2 and/or v8.9.7), as I never remember the Names of the 2 'parseXXX' Methods, ah-ah...!, and it didn't "really" work... But I didn't "insist"/investigate at that time, as I actually use a 4th Solution which is not mentioned but has always worked for me, and which consists of simply multiplying my Var/"String" by 1: [z*1] (without the Brackets), it works and it is shorter in 'EVAL()' than all JS Methods...
a2515125 wrote:i think i make it :)
Thank you!!
the code is below
Code: Select all
SET !REPLAYSPEED FAST
SET !EXTRACT_TEST_POPUP NO
SET !ERRORIGNORE YES
SET !TIMEOUT_PAGE 3
SET !TIMEOUT_STEP 0
SET !LOOP -999
SET !VAR1 EVAL("var z=\"{{!LOOP}}\"; var s = 1000 ; y = s+{{!LOOP}} ; y = (y % 40);if(y == 0){ y = 40};y=y++;")
'prompt {{!VAR1}}
However, I still want to know how to use my own car and set add. My debug still catch undefined when using set my own var
Hum, OK, nice if it works, but you are a bit "lucky" I would think... The Syntax you are now using is a little bit "unreliable", I guess it works on '!LOOP' because of the Reasons I've mentioned above but it probably wouldn't work with any/some other kind of Vars..., at least last time I didn't some "Testing" on using (all kinds of) Vars in 'EVAL()', with Escaped Double-Quotes [\"], Single Quotes ['] or nothing [], but that was several years ago, probably around v8.40 for FF, I think...
More "reliable" in my "Experience" is to declare all Vars at the Beginning of the 'EVAL()' like I do with ["var s='{{!EXTRACT}}', n='{{!LOOP}}', u={{URL_My_Site}}; var x,y,z; ...] and reuse those s/n/u/etc Vars directly in the x/y/z "Building Statements" towards 'z' for the Final Result... This always works and you don't have to worry about (Escaped) Single/Double Quotes, except that you can take for granted that all Vars are probably treated like Strings and you can better convert the ones you need as Number to a Number, even if that is sometimes not needed...
a2515125 wrote:i got another confused that three of my eval scripts are similar but the last one is not working why??
and what is different between
var z={{!LOOP}} and
"var z=\"{{!LOOP}}\"
this working
Code: Select all
SET !VAR1 EVAL("var z={{!LOOP}}; var s = 1000 ; y = s+z ; y = (y % 40);if(y == 0){ y = 40};y=y++;")
this working
Code: Select all
SET !VAR1 EVAL("var z=\"{{!LOOP}}\"; var s = 1000 ; y = s+{{!LOOP}} ; y = (y % 40);if(y == 0){ y = 40};y=y++;")
BUT this not working why?
Code: Select all
SET !VAR1 EVAL("var z=\"{{!LOOP}}\"; var s = 1000 ; y = s+z ; y = (y % 40);if(y == 0){ y = 40};y=y++;")
Same "Story" about "converting a String to a Number", you are a bit "lucky" with the first two Statements, that it works with {{!LOOP}} without any Quotes and 'EVAL()' accepts it directly as a Number, but for the last one, your 'z' is seen as a String I think... (and if you didn't reuse 3x times the same 'y' for all Building Expressions, you could debug the whole 'EVAL()' part by part until you find which part is not "behaving" like you expect... Tja...!, I told you already, that Syntax you are using if for "Advanced" Users who either want to "show off" on a Forum after they've probably extensively tested that Syntax bit by bit, or for "really" Advanced Users who can dream in JS and have some "Built-in" JS Compiler in their Head and know for sure they don't make Mistakes... Good for you, good for them, I'm definitely not at that Level myself, ah-ah...! Hum..., and if you are, you should be answering all Threads on the Forum then, ah-ah...! (Hum, and you would know how to convert a String to a Nb, basic JS Functionality...)).
=> I "suspect" that your first 'y' would be returning "1000-999" as a String, instead of the "1" you expect..., which "screws" of course the next "("1000-999"%40)", the Modulo of a String is probably a bit "ugly", oops...!
>
=> This is how I would have built that 3rd 'EVAL()' of yours...:
Code: Select all
SET !VAR1 EVAL("var n='{{!LOOP}}'; var x,y,z; x=1000+(n*1); y=(x%40); if(y==0){z=41;} else{z=y+1;}; z;")
PROMPT VAR1:<SP>_{{!VAR1}}_
And if you need to change anything in the 'EVAL()', you can debug every single part in it by simply temporarily changing the Return from "z;" to "x;" then "y;"...
A bit "overkill", but that would give stg like:
Code: Select all
SET !VAR1 EVAL("var n='{{!LOOP}}'; var x,y,z; x=1000+(n*1); y=(x%40); if(y==0){z=41;} else{z=y+1;}; x;")
SET !VAR2 EVAL("var n='{{!LOOP}}'; var x,y,z; x=1000+(n*1); y=(x%40); if(y==0){z=41;} else{z=y+1;}; y;")
SET !VAR3 EVAL("var n='{{!LOOP}}'; var x,y,z; x=1000+(n*1); y=(x%40); if(y==0){z=41;} else{z=y+1;}; z;")
PROMPT DEBUG:<BR><BR>x:<SP>_{{!VAR1}}_<BR>y:<SP>_{{!VAR2}}_<BR>z:<SP>_{{!VAR3}}_
By simply changing one single Letter/Char in the 'EVAL()', you can follow and check exactly what each separate Expression in it is doing...
You can try for example to remove the "*1" in "x=1000+(n*1);", maybe it is not needed, and "x=1000+n;" could work directly...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...