iMacros Eval split function

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information:CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
Goldclownfish
Posts: 15
Joined: Mon Apr 29, 2019 3:50 am

iMacros Eval split function

Post by Goldclownfish » Wed May 15, 2019 4:54 am

windows 10 iMacros 11 Pro Imacros Browser

How can i split all the data in a Extract before a

Code: Select all

 [
There is more then one space before the [ as the data constantly changes that i extract. I figure its easier to split at the [ just can not figure out how to do it properly. I suck at regex.
chivracq
Posts: 8323
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: iMacros Eval split function

Post by chivracq » Wed May 15, 2019 4:05 pm

Goldclownfish wrote:
Wed May 15, 2019 4:54 am
windows 10 iMacros 11 Pro Imacros Browser

How can i split all the data in a Extract before a

Code: Select all

 [
There is more then one space before the [ as the data constantly changes that i extract. I figure its easier to split at the [ just can not figure out how to do it properly. I suck at regex.
Hum..., can you give a few concrete and "real" Examples for me to see what is changing and what remains constant in order to find a "generic" Solution...? (Hum, and post the Examples in ']CODE[' Tags, as the Forum otherwise automatically trims double/triple Spaces in Text and Quotes...)

I suck at REGEX too, ah-ah...!, and I never use it, but there is always a Solution with 'split()'..., maybe in combination with 'indexOf()' or 'lastIndexOf()' + 'subtr()' or 'substring()' in your Case...(?)

Hum, or sounds like 'split()' + 'trim()' is what you want, if you want to get rid of all Spaces before the '['... :idea:
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Goldclownfish
Posts: 15
Joined: Mon Apr 29, 2019 3:50 am

Re: iMacros Eval split function

Post by Goldclownfish » Wed May 15, 2019 9:06 pm

Not at home but I’ll post the example of what I need to split when I get there. But yes I would like to leave all the spaces in between the words before the [ but it’s not necessary that I do that. The number of words could change from time to time (all with spaces in between) so for ease I thought it would be a better to split everything before the [ if possible as I can assign it to a var an use it later in the script. What I think your getting at is I should remove all spaces then split the section off before the [ That would be the simplest solution with less chance for errors later on as the next eval command checks to see if the extract match’s a certain set of words. The [ is always in every !EXTRACT an I do not need any data past that. An there is only 1 [ in the extract that never changes.
chivracq
Posts: 8323
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: iMacros Eval split function

Post by chivracq » Wed May 15, 2019 9:31 pm

Goldclownfish wrote:
Wed May 15, 2019 9:06 pm
Not at home but I’ll post the example of what I need to split when I get there. But yes I would like to leave all the spaces in between the words before the [ but it’s not necessary that I do that. The number of words could change from time to time (all with spaces in between) so for ease I thought it would be a better to split everything before the [ if possible as I can assign it to a var an use it later in the script. What I think your getting at is I should remove all spaces then split the section off before the [ That would be the simplest solution with less chance for errors later on as the next eval command checks to see if the extract match’s a certain set of words. The [ is always in every !EXTRACT an I do not need any data past that. An there is only 1 [ in the extract that never changes.
Yeah OK, but not just the Example (singular), but several Examples (plural) as I need to see what remains constant and what can change or I won't be able to give you some "generic" Solution that works for all possible Cases...
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Goldclownfish
Posts: 15
Joined: Mon Apr 29, 2019 3:50 am

Re: iMacros Eval split function

Post by Goldclownfish » Wed May 15, 2019 11:51 pm

Examples of extracted data
Haunted Hollis [RET]'s Name
Scrambled Aggie [PIE]'s Name
New Wave Dave [GAY]'s Name

TAG XPATH="/html/body/div[5]/center/div[1]/div[3]/strong" EXTRACT=TXT
PROMPT _{{!EXTRACT}}_
SET name EVAL("var a = \"{{!EXTRACT}}\".split(\" \"); a[a.length-4];")
'PROMPT _{{name}}_
SET !EXTRACT NULL
SET isname EVAL("var s='{{name}}'; var x; if(s=='Burnt PANCAKES'){x='Yes';} else {x='No';}; x;")
Last edited by Goldclownfish on Thu May 16, 2019 5:34 am, edited 2 times in total.
chivracq
Posts: 8323
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: iMacros Eval split function

Post by chivracq » Thu May 16, 2019 12:41 am

Goldclownfish wrote:
Wed May 15, 2019 11:51 pm
Examples of stripped data

Code: Select all

Haunted Hollis[RET]'s Name
Scrambled Aggie[PIE]'s Name
New Wave Dave [GAY]'s Name

Code: Select all

TAG XPATH="/html/body/div[5]/center/div[1]/div[3]/strong" EXTRACT=TXT
PROMPT _{{!EXTRACT}}_
SET name EVAL("var a = \"{{!EXTRACT}}\".split(\" \"); a[a.length-4];")
'PROMPT _{{name}}_
SET !EXTRACT NULL
SET isname EVAL("var s='{{name}}'; var x; if(s=='Burnt PANCAKES'){x='Yes';} else {x='No';}; x;")
Yeah but your Post is not clear, what is "Haunted Hollis[RET]'s Name"...? Is is the 'EXTRACT'...?, I don't understand what you mean by "stripped data"...?
And do you want "Haunted Hollis" as final Result...?
The first 2 Examples are very similar, and only the 3rd one "New Wave Dave [GAY]'s Name" contains 1 Space before the '['.

But if I understand correctly that you want to keep the part before the '[' and without any Trailing Spaces between that part and the '[', then 'split()' + 'trim()' will do the job, like I already mentioned:

Code: Select all

SET name2 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split('['); y=x[0]; z=y.trim(); z;")
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Goldclownfish
Posts: 15
Joined: Mon Apr 29, 2019 3:50 am

Re: iMacros Eval split function

Post by Goldclownfish » Thu May 16, 2019 5:40 am

All I can get from the split is the space to the left. It late so tomorrow I’ll write the extracts to a file an look at the actual character formatting. I’ve tried several variations of posts that u have in the forum an still only get the space to the left of the [
I mistakenly typed the extracts incorrectly also they all have a space to the left of the [
Sorry for that I’ve been super busy an didn’t want u to think I was not getting back to it. U seem to not particularly like it when people take days to respond. Coding isn’t my real job so it’s only in my free time that I do so an I haven’t had a lot of that lately. Work approximately 70 hours per week. An have two hours of drive time per day.
chivracq
Posts: 8323
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: iMacros Eval split function

Post by chivracq » Fri May 17, 2019 5:49 am

Goldclownfish wrote:
Thu May 16, 2019 5:40 am
All I can get from the split is the space to the left. It late so tomorrow I’ll write the extracts to a file an look at the actual character formatting. I’ve tried several variations of posts that u have in the forum an still only get the space to the left of the [
I mistakenly typed the extracts incorrectly also they all have a space to the left of the [
Sorry for that I’ve been super busy an didn’t want u to think I was not getting back to it. U seem to not particularly like it when people take days to respond. Coding isn’t my real job so it’s only in my free time that I do so an I haven’t had a lot of that lately. Work approximately 70 hours per week. An have two hours of drive time per day.
"Sorry for that I’ve been super busy" + "U seem to not particularly like it when people take days to respond."
=> Yeah well, you are the one choosing the "Timing" when you post your Qt, then yep, you should be a bit "available" to follow up... :o
But tja, stg (unexpected) can always come up "in-between", no Pb to wait for a few days, I'm not always "available" for the Forum myself, heavy Social Life + DJ IRL (just back from a Gig btw), + often shitty Int. Co., then I can't access Internet and the Forum for several hours, or even longer sometimes, then tja..., not much I can do about it... :(

And to be honest, it's always a bit of a hassle when Users don't post the URL to their Site/Page as I can't do any Testing by myself (provided the 'Input' => 'Output' Process has been clearly explained, well..., that I understood it, ah-ah...!), or I completely rely on the "Input" Info you provide, and then on the "Output" Info you provide also for what final Result you want, but you need to be very precise about 'Input' => 'Output'.
And that's already very difficult to explain in "Words", (to be honest, I would "suffer" myself, I think...), and your English is a bit approx also...

Hum, about "difficult to explain in "Words"" + "I would "suffer" myself", I actually most of the time give some Answer in "Words" myself, trying to explain what the/a Solution would/could be, it usually takes me a few mere Seconds to find several (possible) Solutions (that I usually would only need a few min to write in a Script) but I deliberately stopped writing Scripts for other Users 1 or 2 years ago after getting a bit "too often" "too frustrated" from Users not even bothering following up with a mini-"I saw your Post", or a mini-"Thanks" that it solved their Pb... :roll:
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Goldclownfish
Posts: 15
Joined: Mon Apr 29, 2019 3:50 am

Re: iMacros Eval split function

Post by Goldclownfish » Fri May 17, 2019 6:14 am

How do I simply delete all the posts I have ever made an my account? That’s all I need to know at this point.
Post Reply