SOF: Extract Data using EVAL with Triple Separator.

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.
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
chivracq
Posts: 9490
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

SOF: Extract Data using EVAL with Triple Separator.

Post by chivracq » Sun May 10, 2020 12:04 am

Some interesting Thread on SOF from 2 weeks ago, the User was "supposed" to open a parallel Thread on our Forum, but after asking several times and "waiting" with no Follow-up anymore since 10 days, I guess they probably managed to find a Solution, that they probably will never share, so I'm a bit "tired" of waiting and I'm creating this "parallel" Thread "on their behalf"..., before they will eventually delete their Thread on SOF, which happens for more than 50% of Threads/Qt's related to iMacros on that Forum...

Original Thread and Parts of the Comments...:
- Extract Data Using Eval
mizanrobi wrote: Extract Data Using Eval

Asked 14 days ago
Active 12 days ago
Viewed 49 times

Code: Select all

TAG POS=1 TYPE=H1 ATTR=ID:title  EXTRACT=TXT
TAG POS=1 TYPE=SPAN ATTR=ID:acrCustomerReviewText EXTRACT=TXT
TAG POS=1 TYPE=A ATTR=ID:askATFLink EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:\Users\mizanrobi\Desktop FILE=product.csv
with above code I am able to extract 3 things

Code: Select all

Product title: PLUSINNO Telescopic Fishing Rod and Reel Combos Full Kit, Spinning Fishing Gear Organizer Pole Sets with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories

Customer reviews: 666 ratings

Question answered: 180 question was answered among 200
what I want

for customer review and question answered I want only first number: 666 & 180 not text or any other number

and for product title: The text part before first comma (,): PLUSINNO Telescopic Fishing Rod and Reel Combos Full Kit it can be either , or : or - so the product title will be cut off by first (, or : or -)

I know eval can help, but I can not implement.

Thank you.

javascript regex eval imacros

edited Apr 27 at 6:45
asked Apr 25 at 17:33
mizanrobi

... To which I commented...:
chivracq wrote:[...] Case about the Triple Separator for the 'Product title' Field is quite interesting actually, and you may want to open a parallel Thread on the 'iMacros' Forum if you don't get a Solution here from some 'regex' and/or 'javascript' Guru...

(And half of all Threads in the 'Data Extraction' Sub-Forum on that same Forum contain the/a Solution for the 2 other Fields...)

... And then...:
mizanrodi wrote:thanks a lot. I have found solution for last two just need to solve product title issue.

Code: Select all

SET !var3 eval("var s=\"{{!extract}}\"; s=s.split(\" \");s[0];")
working find to extract desire data.

chivracq wrote:Yep, very good...!, even if I prefer a slightly different Syntax, easier to debug, the one you are using is not from me...:

Code: Select all

SET !VAR3 EVAL("var s='{{!EXTRACT}}'; var z=s.split(' '); z[0];")
PROMPT EXTRACT:<SP>_{{!EXTRACT}}_<BR>VAR3:<SP>_{{!VAR3}}_
For 'Product title', you'll need to open a parallel Thread on the iMacros Forum (where I saw you created an Account yesterday) if you still need Help, I don't/rarely answer on this Forum, read my Profile... (Your Qt/OP doesn't comply (yet?) with my "Quality Criteria" anyway...)


I asked them several times to mention their FCI, but they only mentioned at some point:
mizanrobi wrote:... but working for my FF without issue.


And last Comment from me from "yesterday"...:
chivracq wrote:10 days later, any Follow-up...?, or did you find a Sol by yourself...?

Hum, Compliment then, I'm "nearly" Impressed...! Please share it (on this Forum), and open also a Parallel Thread on the iMacros Forum like I had asked you, or I will open it for you as your Scenario is "interesting", but it would be "handier" if you were the "Owner" of that Thread...
>>>

... And I would of course have been "curious" to hear how this User implemented the desired Functionality to extract this "Product title" Field until the first of the 3 possible Separators, a bit like the Functionality in 'Excel' when importing/opening a '.CSV' File, with 5 or 6 possible Separators that can be combined together...

I had several possible Solutions/Implementations in mind, but I think if I had had to implement that Functionality for myself, I would have gone for 'indexOf()' for the 3 Separators, + 'push()' to an Array with a Check on 'indexOf()'>=0 (Char/String not found returns "-1"), and then with 'Math.min()' or 'sort()' on the Array to return the lowest 'indexOf()' Value (>0) to reuse with 'substr()' or 'substring()' on the original Extract... :idea:

And hum, with "only" 3 Separators, it might actually be simpler and shorter to handle all the Conditions with just several 'if'/'else' Statements... :|
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
chivracq
Posts: 9490
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: SOF: Extract Data using EVAL with Triple Separator.

Post by chivracq » Sun May 10, 2020 5:57 pm

Hum..., and would I or anybody else ever want to do some "Testing", I'm posting the Content of this 'Product title' Field as a separate 'Code' Field that can probably be extracted directly as is...:

Code: Select all

Product title: PLUSINNO Telescopic Fishing Rod and Reel Combos Full Kit, Spinning Fishing Gear Organizer Pole Sets with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories
Tja...!, User/@OP never posted the URL, and without URL, it's always a bit cumbersome for other (Advanced) Users to make some (reliable) Testing, grrr...! :roll:

And if the 'Code' Field cannot be extracted "easily", I could add some kind of Separator like "##" for example at the beginning + end of the Content... :wink:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
mizanrobi
Posts: 8
Joined: Sun Apr 26, 2020 6:46 pm

Re: SOF: Extract Data using EVAL with Triple Separator.

Post by mizanrobi » Tue May 12, 2020 8:28 pm

Hi
I am sorry that I was not able to post because I am extremely busy with one of my project, so far I did not find any solution for this
currently I am using

Code: Select all

SET !var7 EVAL("var s=\"{{!EXTRACT}}\"; s=s.replace(/^\\s*|\\s*$/g, \"\");if(s.search(\",\" || \"-\" || \":\")){s=s.split(\",\" || \"-\" || \":\");s[0];};")


which is able to cut first parameter i.e. currently ( , ) separated title
other's parameter ( - ) or ( : )ignored I tried : else, else if else(if) but only first parameter which one I put (either , or - or :) it search and give the result for other's the condition just ignored and give the full title.

Product title can be:

Telescopic Fishing Rod and Reel Combos Full Kit, Spinning Fishing Gear Organizer Pole Sets with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories
Telescopic Fishing Rod and Reel Combos Full Kit-Spinning Fishing Gear Organizer Pole Sets with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories
Telescopic Fishing Rod and Reel Combos Full Kit: Spinning Fishing Gear Organizer Pole Sets with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories

Thank you.
chivracq
Posts: 9490
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: SOF: Extract Data using EVAL with Triple Separator.

Post by chivracq » Tue May 12, 2020 8:45 pm

mizanrobi wrote:
Tue May 12, 2020 8:28 pm
Hi
I am sorry that I was not able to post because I am extremely busy with one of my project, so far I did not find any solution for this
currently I am using

Code: Select all

SET !var7 EVAL("var s=\"{{!EXTRACT}}\"; s=s.replace(/^\\s*|\\s*$/g, \"\");if(s.search(\",\" || \"-\" || \":\")){s=s.split(\",\" || \"-\" || \":\");s[0];};")


which is able to cut first parameter i.e. currently ( , ) separated title
other's parameter ( - ) or ( : )ignored I tried : else, else if else(if) but only first parameter which one I put (either , or - or :) it search and give the result for other's the condition just ignored and give the full title.

Product title can be:

Code: Select all

Telescopic Fishing Rod and Reel Combos Full Kit, Spinning Fishing Gear Organizer Pole Sets with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories

Code: Select all

Telescopic Fishing Rod and Reel Combos Full Kit-Spinning Fishing Gear Organizer Pole Sets with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories

Code: Select all

Telescopic Fishing Rod and Reel Combos Full Kit: Spinning Fishing Gear Organizer Pole Sets with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories
Thank you.

Alright...!, youpidoo...! Nice to see you "finally" on our Forum...! Good-good...! :D :wink:

But-but-but..., nice try, but now the Forum Rules for "our" Forum apply, so please read them, ... and that will "speed up" the "Process" for me to help and do any "Thinking"..., I had mentioned that your Thread on SOF didn't "comply with my Quality Criteria" and I had asked you several times to mention your FCI, to no avail unfortunately, so now you still have to comply... :idea:
=> FCIM...! :mrgreen: (Read my Sig also...)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
mizanrobi
Posts: 8
Joined: Sun Apr 26, 2020 6:46 pm

Re: SOF: Extract Data using EVAL with Triple Separator.

Post by mizanrobi » Wed May 13, 2020 7:48 pm

Hi
Thanks a lot. I am using trial version of imacros enterprise edition on window 10 32 bit.
I have another thing I am working on I will make another post either I found solution or I need help.

Thank you.
chivracq
Posts: 9490
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: SOF: Extract Data using EVAL with Triple Separator.

Post by chivracq » Wed May 13, 2020 8:06 pm

mizanrobi wrote:
Wed May 13, 2020 7:48 pm
Hi
Thanks a lot. I am using

Code: Select all

trial version of imacros enterprise edition on window 10 32 bit.
I have another thing I am working on I will make another post either I found solution or I need help.

Thank you.

Hum, OK, but you don't mention the Version, ah-ah...!? :?

"Current" Version would "normally" be iMB v12.6, but tja..., we regularly see (New) Users on the Forum (still) using some iMB v10.x "Trial" Version, while those Versions are now about 6 years old, that I don't dare to "guess for sure" you'll be indeed using v12.6. :?
=> Simply mention the (exact) Version...?

Hum, and I'm a bit "confused" also because you had previously mentioned "... but working for my FF without issue.", so I had understood you were using "some" Version of iMacros for FF..., but iMB (any Version) is a completely different Browser than FF... ("iMB" = "iMacros Browser") :?
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
mizanrobi
Posts: 8
Joined: Sun Apr 26, 2020 6:46 pm

Re: SOF: Extract Data using EVAL with Triple Separator.

Post by mizanrobi » Wed May 13, 2020 8:43 pm

sorry version is 12.6 the latest one. thank you.
chivracq
Posts: 9490
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: SOF: Extract Data using EVAL with Triple Separator.

Post by chivracq » Wed May 13, 2020 9:51 pm

mizanrobi wrote:
Wed May 13, 2020 8:43 pm
sorry version is 12.6 the latest one. thank you.

Alright then, we finally have your FCI: :D

Code: Select all

iMB v12.6 'Trial', Win10_x32.
Hum..., and when helping Users on our Forum who've also opened a parallel Thread on SOF, I "normally" ask them to also add their FCI to their OP/Qt on SOF..., but OK, don't worry..., as I guess you'll probably delete your Thread on SOF once you'll have your Solution/Script working..., like most Users do on that Forum..., fair enough... (Even if I don't help anymore afterwards, when Users delete their Thread(s) on SOF, but I don't have any "Way" to enforce it...) :|

>>>

OK, then "next step", hum, you didn't react/explain about me/you mentioning FF previously, OK, no big deal, but I'll be asking my Qt's one by one or you each time only react "selectively" to 1 if I ask several Qt's or make several Suggs in one Post...

Now, what is your Global 'replace()' supposed to do in your "s=s.replace(/^\\s*|\\s*$/g, \"\");"...? :?:

I never use this Global 'replace()' Syntax that I find "complicated" to understand, (and I never use REGEXP either), I prefer to use another Method/Syntax, but I need to know what your Sub-Statement is "supposed to do", in order to be able to adapt it to "my" Syntax, or to use yours, but I need to know what "Result"/Behaviour to expect..., especially the "/^\\s*|\\s*$" part, the rest I understand... :wink:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
mizanrobi
Posts: 8
Joined: Sun Apr 26, 2020 6:46 pm

Re: SOF: Extract Data using EVAL with Triple Separator.

Post by mizanrobi » Thu May 14, 2020 5:56 pm

Hi
thanks a lot. I am really sorry to answer after you ask. You have already mentioned me about this FCI before so I should be careful about it, I believe any new thread I create on the forum will mention the FCI at the first hand. Please accept my apology.

s=s.replace(/^\\s*|\\s*$/g, \"\"); the regular expression I am using to trim leading space. when I am extracting data in my csv file it comes with leading space for product title, so I use this regular expression to trim leading space.

Note that this piece of code does not effect on my rest of code means the condition I use does not change result if I remove this regular expression code.

Thank you.
chivracq
Posts: 9490
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: SOF: Extract Data using EVAL with Triple Separator.

Post by chivracq » Thu May 14, 2020 11:43 pm

mizanrobi wrote:
Thu May 14, 2020 5:56 pm
Hi
thanks a lot. I am really sorry to answer after you ask. You have already mentioned me about this FCI before so I should be careful about it, I believe any new thread I create on the forum will mention the FCI at the first hand. Please accept my apology.

s=s.replace(/^\\s*|\\s*$/g, \"\"); the regular expression I am using to trim leading space. when I am extracting data in my csv file it comes with leading space for product title, so I use this regular expression to trim leading space.

Note that this piece of code does not effect on my rest of code means the condition I use does not change result if I remove this regular expression code.

Thank you.

Ah..., OK for the "Trim" Functionality, well then, you could simply use the 'trim()' Method instead...! :P

Then OK, I did "a little bit" of Testing, you'll get a "long Version", and a "Short Version", ah-ah...!, even if I guess you'll only be interested by the "Short Version", but OK, fair enough... :|

So OK, I had a "Look" at your proposed 'EVAL()' Statement:

Code: Select all

SET !var7 EVAL("var s=\"{{!EXTRACT}}\"; s=s.replace(/^\\s*|\\s*$/g, \"\");if(s.search(\",\" || \"-\" || \":\")){s=s.split(\",\" || \"-\" || \":\");s[0];};")
... Then hum, OK, so you didn't go at all for the Method I had suggested, even if it works, your Sol/Implementation would indeed be "simpler" than the one I had suggested, even if 'search()' does the same like 'indexOf()' I had mentioned, although I'm not sure 'indexOf()' can use Multiple Args, but they both return an Index, and "-1" if not/none Found which is what your Expression always returns.

And I think also the Syntax you are using for 'search()' is incorrect... (I tried it in my "Long Version" Script, it always returns "-1", I think...) I'm not a JavaScript Guru, but correct would be:

Code: Select all

s.search(',|-|:|');
..., or you can also replace the Single Quotes by Escaped Double Quotes, that should work also, but I always try to use Single Quotes inside 'EVAL()' as they (most of the time) don't need to be Escaped...

Your 'if' Condition will never do anything I think, as I think it is incomplete, 'search()' returns an Index, not a Boolean.

Then I thought, hum interesting, I didn't "know", well never tried, because I never needed the Functionality I guess, that 'split()' could use Multiple Args, hum-hum, good to know... But nope, it doesn't work, ah-ah...!! (It always only uses the 1st Arg, like you found out...) :(

>>>

Then alright, here is the "Long Version" of the (Debug) Script I used:

Code: Select all

VERSION BUILD=8820413 RECORDER=FX
SET !EXTRACT_TEST_POPUP NO
TAB T=1
URL GOTO=https://forum.imacros.net/viewtopic.php?f=7&t=31007&p=85387#p85387

TAG POS=2 TYPE=DIV ATTR=TXT:mizanrobi<SP>wrote:<SP>↑12/05/2020<SP>-<SP>22:28HiI<SP>am*
SET PROMPT_Debug PROMPT_Debug:<BR><BR>

'SET !EXTRACT "Telescopic Fishing Rod and Reel Combos Full Kit, Spinning Fishing Gear Organizer Pole Sets with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories"
SET !EXTRACT "Telescopic Fishing Rod: and Reel Combos Full-Kit, Spinning Fishing Gear-Organizer, Pole Sets: with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories"
SET Split_All EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.match(',|-|:'); y=s.split(x); z=y[0]; z;")
ADD PROMPT_Debug EXTRACT:<SP>(,-:)<BR>_{{!EXTRACT}}_
ADD PROMPT_Debug <BR>Split_All:<SP>_{{Split_All}}_
ADD PROMPT_Debug <BR><BR>'>>><BR><BR>

TAG POS=8 TYPE=P ATTR=TXT:Code:<SP>Select<SP>all
SET !EXTRACT NULL
TAG POS=1 TYPE=CODE ATTR=TXT:Telescopic<SP>Fishing<SP>Rod<SP>and<SP>Reel<SP>Combos<SP>Ful* EXTRACT=TXT
SET !VAR1 EVAL("var s=\"{{!EXTRACT}}\"; s=s.replace(/^\\s*|\\s*$/g, \"\");if(s.search(\",\" || \"-\" || \":\")){s=s.split(\",\" || \"-\" || \":\");s[0];};")
SET Rst_Search_1 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(\",\" || \"-\" || \":\"); x;")
SET Rst_Search_12 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(',|-|:'); x;")
'SET Split_All EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split(',|-|:'); x[0];")
SET Split_All EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.match(',|-|:'); y=s.split(x); z=y[0]; z;")
'>
SET Rst_Search_Comma EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(','); x;")
SET Rst_Search_Dash EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search('-'); x;")
SET Rst_Search_Colon EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(':'); x;")
'>
'SET Rst_Search_Comma EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(\\/,\\/gi); x;")
'SET Rst_Search_Dash EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(\\/-\\/gi); x;")
'SET Rst_Search_Colon EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(\\/:\\/gi); x;")
'>
SET Rst_Index_Comma EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.indexOf(','); x;")
SET Rst_Index_Dash EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.indexOf('-'); x;")
SET Rst_Index_Colon EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.indexOf(':'); x;")
'>
ADD PROMPT_Debug EXTRACT:<SP>(,)<BR>_{{!EXTRACT}}_<BR><BR>VAR1_(,):<BR>_{{!VAR1}}_
ADD PROMPT_Debug <BR>Rst_Search_1:<SP>_{{Rst_Search_1}}_<BR>Rst_Search_12:<SP>_{{Rst_Search_12}}_
ADD PROMPT_Debug <BR>Split_All:<SP>_{{Split_All}}_
ADD PROMPT_Debug <BR>Search_Comma:<SP>_{{Rst_Search_Comma}}_<BR>Search_Dash:<SP>_{{Rst_Search_Dash}}_<BR>Search_Colon:<SP>_{{Rst_Search_Colon}}_
ADD PROMPT_Debug <BR>Index_Comma:<SP>_{{Rst_Index_Comma}}_<BR>Index_Dash:<SP>_{{Rst_Index_Dash}}_<BR>Index_Colon:<SP>_{{Rst_Index_Colon}}_
ADD PROMPT_Debug <BR><BR>'>>><BR><BR>
'PAUSE

TAG POS=9 TYPE=P ATTR=TXT:Code:<SP>Select<SP>all
SET !EXTRACT NULL
TAG POS=2 TYPE=CODE ATTR=TXT:Telescopic<SP>Fishing<SP>Rod<SP>and<SP>Reel<SP>Combos<SP>Ful* EXTRACT=TXT
SET !VAR2 EVAL("var s=\"{{!EXTRACT}}\"; s=s.replace(/^\\s*|\\s*$/g, \"\");if(s.search(\",\" || \"-\" || \":\")){s=s.split(\",\" || \"-\" || \":\");s[0];};")
SET Rst_Search_2 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(\",\" || \"-\" || \":\"); x;")
SET Rst_Search_22 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(',|-|:'); x;")
'SET Split_All EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split(',|-|:'); x[0];")
SET Split_All EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.match(',|-|:'); y=s.split(x); z=y[0]; z;")
'>
SET Rst_Search_Comma EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(','); x;")
SET Rst_Search_Dash EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search('-'); x;")
SET Rst_Search_Colon EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(':'); x;")
'>
ADD PROMPT_Debug EXTRACT:<SP>(-)<BR>_{{!EXTRACT}}_<BR><BR>VAR2_(-):<BR>_{{!VAR2}}_
ADD PROMPT_Debug <BR>Rst_Search_2:<SP>_{{Rst_Search_2}}_<BR>Rst_Search_22:<SP>_{{Rst_Search_22}}_
ADD PROMPT_Debug <BR>Split_All:<SP>_{{Split_All}}_
ADD PROMPT_Debug <BR>Search_Comma:<SP>_{{Rst_Search_Comma}}_<BR>Search_Dash:<SP>_{{Rst_Search_Dash}}_<BR>Search_Colon:<SP>_{{Rst_Search_Colon}}_
ADD PROMPT_Debug <BR><BR>'>>><BR><BR>
'PAUSE

TAG POS=10 TYPE=P ATTR=TXT:Code:<SP>Select<SP>all
SET !EXTRACT NULL
TAG POS=3 TYPE=CODE ATTR=TXT:Telescopic<SP>Fishing<SP>Rod<SP>and<SP>Reel<SP>Combos<SP>Ful* EXTRACT=TXT
SET !VAR3 EVAL("var s=\"{{!EXTRACT}}\"; s=s.replace(/^\\s*|\\s*$/g, \"\");if(s.search(\",\" || \"-\" || \":\")){s=s.split(\",\" || \"-\" || \":\");s[0];};")
SET Rst_Search_3 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(\",\" || \"-\" || \":\"); x;")
SET Rst_Search_32 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(',|-|:'); x;")
'SET Split_All EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split(',|-|:'); x[0];")
SET Split_All EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.match(',|-|:'); y=s.split(x); z=y[0]; z;")
'>
SET Rst_Search_Comma EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(','); x;")
SET Rst_Search_Dash EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search('-'); x;")
SET Rst_Search_Colon EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.search(':'); x;")
'>
ADD PROMPT_Debug EXTRACT:<SP>(:)<BR>_{{!EXTRACT}}_<BR><BR>VAR3_(:):<BR>_{{!VAR3}}_
ADD PROMPT_Debug <BR>Rst_Search_3:<SP>_{{Rst_Search_3}}_<BR>Rst_Search_32:<SP>_{{Rst_Search_32}}_
ADD PROMPT_Debug <BR>Split_All:<SP>_{{Split_All}}_
ADD PROMPT_Debug <BR>Search_Comma:<SP>_{{Rst_Search_Comma}}_<BR>Search_Dash:<SP>_{{Rst_Search_Dash}}_<BR>Search_Colon:<SP>_{{Rst_Search_Colon}}_

PROMPT {{PROMPT_Debug}}
... Which returns in the 'PROMPT':

Code: Select all

PROMPT_Debug:

EXTRACT: (,-:)
_Telescopic Fishing Rod: and Reel Combos Full-Kit, Spinning Fishing Gear-Organizer, Pole Sets: with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories_
Split_All: _Telescopic Fishing Rod_

'>>>

EXTRACT: (,)
_Telescopic Fishing Rod and Reel Combos Full Kit, Spinning Fishing Gear Organizer Pole Sets with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories_

VAR1_(,):
_Telescopic Fishing Rod and Reel Combos Full Kit_
Rst_Search_1: _47_
Rst_Search_12: _47_
Split_All: _Telescopic Fishing Rod and Reel Combos Full Kit_
Search_Comma: _47_
Search_Dash: _-1_
Search_Colon: _-1_
Index_Comma: _47_
Index_Dash: _-1_
Index_Colon: _-1_

'>>>

EXTRACT: (-)
_Telescopic Fishing Rod and Reel Combos Full Kit-Spinning Fishing Gear Organizer Pole Sets with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories_

VAR2_(-):
_Telescopic Fishing Rod and Reel Combos Full Kit-Spinning Fishing Gear Organizer Pole Sets with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories_
Rst_Search_2: _-1_
Rst_Search_22: _47_
Split_All: _Telescopic Fishing Rod and Reel Combos Full Kit_
Search_Comma: _-1_
Search_Dash: _47_
Search_Colon: _-1_

'>>>

EXTRACT: (:)
_Telescopic Fishing Rod and Reel Combos Full Kit: Spinning Fishing Gear Organizer Pole Sets with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories_

VAR3_(:):
_Telescopic Fishing Rod and Reel Combos Full Kit: Spinning Fishing Gear Organizer Pole Sets with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories_
Rst_Search_3: _-1_
Rst_Search_32: _47_
Split_All: _Telescopic Fishing Rod and Reel Combos Full Kit_
Search_Comma: _-1_
Search_Dash: _-1_
Search_Colon: _47_
>>>

And here is the "Short Version", that works thus...:

Code: Select all

VERSION BUILD=8820413 RECORDER=FX
SET !EXTRACT_TEST_POPUP NO
TAB T=1
'URL GOTO=https://forum.imacros.net/viewtopic.php?f=7&t=31007&p=85387#p85387

'SET !EXTRACT "Telescopic Fishing Rod and Reel Combos Full Kit, Spinning Fishing Gear Organizer Pole Sets with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories"
SET !EXTRACT "Telescopic Fishing Rod: and Reel Combos Full-Kit, Spinning Fishing Gear-Organizer, Pole Sets: with Line Lures Hooks Reel and Fishing Carrier Bag Case Accessories"
SET Split_All EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.match(',|-|:'); y=s.split(x); z=y[0]; z;")

SET PROMPT_Debug PROMPT_Debug:<BR><BR>
ADD PROMPT_Debug EXTRACT:<SP>(,-:)<BR>_{{!EXTRACT}}_
ADD PROMPT_Debug <BR>Split_All:<SP>_{{Split_All}}_
PROMPT {{PROMPT_Debug}}
(Written and Tested on iMacros for FF v8.8.2, PM v26.3.3, Win10_x64.)

So it uses 'match()' that apparently returns the first of the 3 Separators, which is then reused for the 'split()'. Fairly simple...! 8)

Some other Solution could have been to use "your" 'search()', but then you need to use 'substring()' or 'substr()' instead of 'split()' like I had suggested... :idea:

I expected for the "x" in "y=s.split(x);" to have to specify "x[0]" in case of more than 1 of the 3 Separators to be present in the 'EXTRACT', but apparently, that's not needed, even if it works also with "x[0]" (=> y=s.split(x[0]);), but strangely enough, it doesn't work anymore with "x[1]"... I didn't investigate why as you want the 1st one anyway... :o

Oh yeah, and if you want to re-add the Trim Functionality, then that would give:

Code: Select all

SET Split_All EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.trim(); y=x.match(',|-|:'); z=x.split(y); z[0];")
(Not tested, as the "EXTRACT"('s) I was able to use were already "clean"...)

Alright, see/check/test/confirm if it works for you also, on your "real" Site and with different "Examples", you never posted the URL of the Site, so I couldn't do some "real" Testing on it, and once you are "Happy" with that Solution, I will post it as "Answer" on SOF also... 8)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
mizanrobi
Posts: 8
Joined: Sun Apr 26, 2020 6:46 pm

Re: SOF: Extract Data using EVAL with Triple Separator.

Post by mizanrobi » Fri May 15, 2020 1:01 am

Hi
Thanks a lot for great help. I use the below code from your suggestion and it works perfectly. thanks a lot.

Code: Select all

SET !VAR7 EVAL("var s=\"{{!EXTRACT}}\"; s=s.replace(/^\\s*|\\s*$/g, \"\");if(s.search(/-|,|:/)){s=s.split(/-|,|:/);s[0];};")


Thank You
chivracq
Posts: 9490
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: SOF: Extract Data using EVAL with Triple Separator.

Post by chivracq » Fri May 15, 2020 2:28 am

mizanrobi wrote:
Fri May 15, 2020 1:01 am
Hi
Thanks a lot for great help. I use the below code from your suggestion and it works perfectly. thanks a lot.

Code: Select all

SET !VAR7 EVAL("var s=\"{{!EXTRACT}}\"; s=s.replace(/^\\s*|\\s*$/g, \"\");if(s.search(/-|,|:/)){s=s.split(/-|,|:/);s[0];};")


Thank You

Hum, you are a bit "lucky", because the 'if' and the 'search()' have no Use and do nothing as far as I can tell, and the Syntax you keep using is very difficult to debug with 'EVAL()'... :|
But you are right that the Multiple 'split()' is actually working with Forward Slashes, I had only tried with Single Quotes, so it's the 'split()' that is doing all the Magic, this one works also...: 8)

Code: Select all

SET Split_All EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.trim(); y=x.split(/-|,|:/); z=y[0]; z;")
(Tested on iMacros for FF v8.8.2, PM v26.3.3, Win10_x64.)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
mizanrobi
Posts: 8
Joined: Sun Apr 26, 2020 6:46 pm

Re: SOF: Extract Data using EVAL with Triple Separator.

Post by mizanrobi » Fri May 15, 2020 6:37 pm

thanks a lot. yes you are absolutely right, there is no need of if and search(). I just removed them. I think the issue is solved. thanks a lot for your great help.

And I have just noticed I have no option to create new thread, do not why or am I missing something.

Thank you.
chivracq
Posts: 9490
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: SOF: Extract Data using EVAL with Triple Separator.

Post by chivracq » Fri May 15, 2020 7:11 pm

mizanrobi wrote:
Fri May 15, 2020 6:37 pm
thanks a lot. yes you are absolutely right, there is no need of if and search(). I just removed them. I think the issue is solved. thanks a lot for your great help.

And I have just noticed I have no option to create new thread, do not why or am I missing something.

Thank you.

OK, I will post a "condensed" Version of the different Solutions as "Answer" on SOF, for you to "accept"...

>>>

I declined of course your Request to join the 'Moderator' Group, in your Dreams, ah-ah...! :P

>>>

Well, to open a New Thread, you need to start from the "Main" Index Page, => see the "Board Index" Link at the top and bottom of nearly all Pages on the Forum, then to select the "correct" Sub-Forum in which you want to open your Thread, and then you'll see a "NEW TOPIC" Button at the top of a Sub-Forum...

And make sure to read the Forum Rules before opening your Thread, I won't go for example through the Hassle again of getting you to mention your FCI... :!:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
mizanrobi
Posts: 8
Joined: Sun Apr 26, 2020 6:46 pm

Re: SOF: Extract Data using EVAL with Triple Separator.

Post by mizanrobi » Sat May 16, 2020 6:07 pm

thanks a lot. I was able to post. No sorrow about being moderator may I did that withing understanding meaning. :D
As I have less experience to be active on a forum.

Thank you.
Post Reply