How do I structure a code to auto copy any text in a pattern XXXXX-XXXXX-XXXXX-XXXXX-XXXXX ?

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

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
bb1000
Posts: 17
Joined: Tue Dec 03, 2019 3:14 pm

How do I structure a code to auto copy any text in a pattern XXXXX-XXXXX-XXXXX-XXXXX-XXXXX ?

Post by bb1000 » Tue Dec 10, 2019 12:24 am

How do I structure a code to auto copy any text in a pattern XXXXX-XXXXX-XXXXX-XXXXX-XXXXX ? This pattern will always have 5 letters then a (-) 5 times. Scattered with numbers and letters, for example EB3DA-JRDFF-EN733-E3YXD-P7Z6G. I have been able to make a code to auto copy text, but not unknown text. I'm using "VERSION BUILD=1005 RECORDER=CR" on Google Chrome Version 78.0.3904.108 (Official Build)
This is what I have tried...

VERSION BUILD=1005 RECORDER=CR
SET !EXTRACT_TEST_POPUP NO
TAG POS=1 TYPE=* ATTR=TXT:* EXTRACT=TXT
SET !CLIPBOARD {{!EXTRACT}}


Help would be much appreciated. Thanks in advance.
Last edited by bb1000 on Wed Dec 11, 2019 6:49 pm, edited 1 time in total.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How do I structure a code to auto copy any text in a pattern XXXXX-XXXXX-XXXXX-XXXXX-XXXXX ?

Post by chivracq » Tue Dec 10, 2019 12:58 am

bb1000 wrote:
Tue Dec 10, 2019 12:24 am
How do I structure a code to auto copy any text in a pattern XXXXX-XXXXX-XXXXX-XXXXX-XXXXX ? This pattern will always have 5 letters then a (-) 5 times. Scattered with numbers and letters, for example EB3DA-JRDFF-EN733-E3YXD-P7Z6G. I have been able to make a code to auto copy text, but not unknown text.

I'm using

Code: Select all

"VERSION BUILD=1005 RECORDER=CR" on Google Chrome Version 78.0.3904.108 (Official Build) (64-bit). 
This is what I have tried...

Code: Select all

VERSION BUILD=1005 RECORDER=CR
SET !EXTRACT_TEST_POPUP NO
TAG POS=1 TYPE=* ATTR=TXT:* EXTRACT=TXT
SET !CLIPBOARD {{!EXTRACT}}

Help would be much appreciated. Thanks in advance.

Oh, good...! Nice to see you've "also" discovered our Forum, 11 days after first posting your Qt on SOF, ... which I didn't answer as you had not mentioned your FCI...: 8)
- How do I set unknown values on iMacros?
(No Replies, FCI not mentioned...)

FCIM...! :mrgreen: (Read my Sig...)
'Free'/'PE' + OS are missing... :P

Try to select the "correct" Sub-Forum when you open a Thread on our Forum, this one has nothing specific to the 'iMacros for CR' one..., would have been the 'Data Extraction' one, where this Thread will probably get moved to...

Mention your FCI and I would have a few "Ideas"/Suggs concerning your Scenario... 8)
Any chance you could post the URL for this Site/Page, to have a look at the HTML Structure of the Page, Nb of Occurrences, exact Formatting, etc...?
And I will ask you to also mention your FCI on SOF to maintain the same "Quality" on both Forums... :wink:
( :!: And I stop helping if you delete your parallel Thread on SOF... where we'll be able to post the "final" Solution...)
- (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...
bb1000
Posts: 17
Joined: Tue Dec 03, 2019 3:14 pm

Re: How do I structure a code to auto copy any text in a pattern XXXXX-XXXXX-XXXXX-XXXXX-XXXXX ?

Post by bb1000 » Tue Dec 10, 2019 1:41 am

Hi there, apologies about my previous thread...I will also update my system information etc on SOF😁 Thanks for the help too, I really do appreciate it. I've been looking for ages and cannot find a way to do it, so I've finally found the right place :D

There is no specific site. I want to monitor Discord channels to look for this format. So that if someone posts a serial number e.g. NXG4K-YRLVF-44JLD-KH5H2-ZBBX7 it would automatically copy that to clipboard. Anything in that specific format (XXXXX-XXXXX-XXXXX-XXXXX-XXXXX).

I am using macOS 10.14.6 with iMacros free on Google Chrome Version 78.0.3904.108 (Official Build) (64-bit)

Thanks again :)
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How do I structure a code to auto copy any text in a pattern XXXXX-XXXXX-XXXXX-XXXXX-XXXXX ?

Post by chivracq » Tue Dec 10, 2019 2:16 am

bb1000 wrote:
Tue Dec 10, 2019 1:41 am
Hi there, apologies about my previous thread... Thanks for the help too, I really do appreciate it. I've been looking for ages and cannot find a way to do it, so I've finally found the right place :D

There is no specific site. I want to monitor Discord channels to look for this format. So that if someone posts a serial number e.g. NXG4K-YRLVF-44JLD-KH5H2-ZBBX7 it would automatically copy that to clipboard. Anything in that specific format (XXXXX-XXXXX-XXXXX-XXXXX-XXXXX).

I am using

Code: Select all

macOS 10.14.6 with iMacros free on Google Chrome Version 78.0.3904.108 (Official Build) (64-bit)
Thanks again :)

OK, Thanks for your FCI... There is no 'PE' Version on MacOS for v10.0.5 for CR indeed, only the 'Free' one...

Well, no need to apologize about your Thread on SOF, it's perfectly fine to open parallel Threads on different Tech Forums to increase your "Chances" to get some Help/Solution, ... as long as you maintain the same "Quality" on both... :wink:
And "Quality" means mentioning your FCI + neat Follow-up + sharing your Solution/Final Script (and not deleting your Thread/Qt on SOF like most Users on that Forum do), Reason I asked you to also mention your FCI in your Thread/Qt on SOF..., but you haven't complied yet... :(
- (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...
bb1000
Posts: 17
Joined: Tue Dec 03, 2019 3:14 pm

Re: How do I structure a code to auto copy any text in a pattern XXXXX-XXXXX-XXXXX-XXXXX-XXXXX ?

Post by bb1000 » Tue Dec 10, 2019 2:26 am

I have just added my system information onto SOF😁Appreciate the tips!!

Do you have a few ideas to help me with my iMacros??
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How do I structure a code to auto copy any text in a pattern XXXXX-XXXXX-XXXXX-XXXXX-XXXXX ?

Post by chivracq » Tue Dec 10, 2019 3:28 am

bb1000 wrote:
Tue Dec 10, 2019 2:26 am
I have just added my system information onto SOF😁Appreciate the tips!!

Do you have a few ideas to help me with my iMacros??

Alright, good...! :D

Then OK, concerning your Scenario, a "quick and dirty" and easy Implementation would be to simply use:

Code: Select all

TAG POS=1 TYPE=* ATTR=TXT:*-*-*-*-* EXTRACT=TXT
... But this will extract "anything" on the Page containing 4 Dashes, and because of your "TYPE=*", this would for example also extract the whole Page if there are for example 2 Dates like in:
[...] ... 2019-12-10 ...
[...]
... 2020-02-22 ...
... or if anybody had a structured Msg like in:
1- Do that...
2- Or do that...
3- Or you can also do that...
4- Or that also...
=> This will probably find a lot of "false" Positives...

You would need to already narrow the possible Matches by using the exact 'TYPE' Element(s) you expect on that Page, a 'DIV' probably, together with some specific Attribute(s) like the Class which probably remains constant.

You could also maybe include the Word "serial" in the Search:

Code: Select all

TAG POS=1 TYPE=* ATTR=TXT:*serial*-*-*-*-* EXTRACT=TXT
And then using 'EVAL()' you could also add a bit of "Intelligence" to check if what got extracted looks a bit like the Format you expect, using 'match()' and/or 'spit()' and the 'Length' of the several 'split()' parts between the 4 Dashes, including the next 5 Chars before and after the 1st and the 4th Dashes...

Using the 'TAG XPATH' Mode, you would be able to further narrow the Matches/Extracts to Text containing exactly the Format that you expect, but you will still need 'EVAL()' to clean up the '!EXTRACT' and isolate only that SN, because 'EXTRACT' will still extract the whole Text/HTML Element containing the SN...

iMacros also has a 'SEARCH' Command but I find the Method where the Search is already (partially) defined using the 'ATTR=TXT' Attribute like I mentioned much easier to use as it doesn't require 'REGEXP' like 'SEARCH' and 'match()' do... (And 'split()' can do (almost) everything that 'match()' can do...)
- (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...
bb1000
Posts: 17
Joined: Tue Dec 03, 2019 3:14 pm

Re: How do I structure a code to auto copy any text in a pattern XXXXX-XXXXX-XXXXX-XXXXX-XXXXX ?

Post by bb1000 » Tue Dec 10, 2019 1:05 pm

I really appreciate your reply! Thanks a lot☺️ I’m pretty new to this and understand most things, but am unsure how to include them into my code... Could you please write the full code for what you said about EVAL etc. ?

That would really help a lot. Especially for future reference when I struggle with other things within iMacros😛

Thanks in advance.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How do I structure a code to auto copy any text in a pattern XXXXX-XXXXX-XXXXX-XXXXX-XXXXX ?

Post by chivracq » Tue Dec 10, 2019 2:06 pm

bb1000 wrote:
Tue Dec 10, 2019 1:05 pm
I really appreciate your reply! Thanks a lot☺️ I’m pretty new to this and understand most things, but am unsure how to include them into my code... Could you please write the full code for what you said about EVAL etc. ?

That would really help a lot. Especially for future reference when I struggle with other things within iMacros😛

Thanks in advance.

Yeah well, I would need a "concrete Example" to be able to write (and test) a "full code", => Reason I had asked if you could post the/a URL for your Site/Page...; iMacros Scripts are always very specific to the specific HTML Structure of a given Page..., + Reason also my previous Reply contains a lot of "could-could-could" because without a concrete Script and a concrete URL/Site, I can only give you some "Generic" Advice, as your "TAG POS=1 TYPE=^ ATTR=TXT:*" doesn't tell me anything at all about the HTML Structure of your Site/Page, this Statement would work on absolutely any Page on any Website on the whole Internet... It's just like doing a 'Ctrl^a' + 'Ctrl^c' on any Page to select the whole Content of the Page... :|

And/BUT...!, I don't write "full code"/Scripts for other Users, or very-very rarely... :shock:
I let Users understand "what they are doing" and "how it works" and what "is possible", and I let them find the/a Solution by themselves, and I only "jump again"/dive into their Script if they "really" get stuck, but I won't be writing your Script, ah-ah...! :P

The Forum already contains 100's of 'EVAL()' Statements if you need some Examples, and many written by me, and I strive to use an "easy" Syntax to understand and follow (for Beginners, I'm no JavaScript Guru myself either...) and reuse and extend (and which is also easy to debug, very important...!) for (more) complex Scenarios, but now it's your turn "to dig in the mud", ah-ah...! :wink:
- (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...
bb1000
Posts: 17
Joined: Tue Dec 03, 2019 3:14 pm

Re: How do I structure a code to auto copy any text in a pattern XXXXX-XXXXX-XXXXX-XXXXX-XXXXX ?

Post by bb1000 » Tue Dec 10, 2019 2:25 pm

There is no need for the url/HTML as I would want this to work on all sites. I have been looking around for solutions for weeks now, way before I posted on SOF. I am really stuck in the mud and that’s no jokes🤦‍♂️I would just want this method to work on any url so that I can start the iMacros and if anything in that format would come up it would copy the text, no need for a specific url😛
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How do I structure a code to auto copy any text in a pattern XXXXX-XXXXX-XXXXX-XXXXX-XXXXX ?

Post by chivracq » Tue Dec 10, 2019 2:32 pm

bb1000 wrote:
Tue Dec 10, 2019 2:25 pm
There is no need for the url/HTML as I would want this to work on all sites. I have been looking around for solutions for weeks now, way before I posted on SOF. I am really stuck in the mud and that’s no jokes🤦‍♂️I would just want this method to work on any url so that I can start the iMacros and if anything in that format would come up it would copy the text, no need for a specific url😛

Yeah well, then use 'SEARCH' + 'REGEXP', that's the Purpose of that Command... :idea:
- (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...
bb1000
Posts: 17
Joined: Tue Dec 03, 2019 3:14 pm

Re: How do I structure a code to auto copy any text in a pattern XXXXX-XXXXX-XXXXX-XXXXX-XXXXX ?

Post by bb1000 » Tue Dec 10, 2019 2:37 pm

I really appreciate your help😁I’ll have a go when I’m back home! If I need help after I’ve made the code etc to see where I’ve made an error if so, I’ll come straight back here! Thanks a lot.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How do I structure a code to auto copy any text in a pattern XXXXX-XXXXX-XXXXX-XXXXX-XXXXX ?

Post by chivracq » Tue Dec 10, 2019 2:40 pm

bb1000 wrote:
Tue Dec 10, 2019 2:37 pm
I really appreciate your help😁I’ll have a go when I’m back home! If I need help after I’ve made the code etc to see where I’ve made an error if so, I’ll come straight back here! Thanks a lot.

Yep, "good Luck"... :wink:

And come back anyway, to also post/share your Final/Working Script... 8)
- (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...
bb1000
Posts: 17
Joined: Tue Dec 03, 2019 3:14 pm

Re: How do I structure a code to auto copy any text in a pattern XXXXX-XXXXX-XXXXX-XXXXX-XXXXX ?

Post by bb1000 » Wed Dec 11, 2019 5:53 pm

Final Script:

VERSION BUILD=1005 RECORDER=CR
SET !ERRORIGNORE YES
SET !TIMEOUT 100000
SET !EXTRACT_TEST_POPUP NO
SEARCH SOURCE=REGEXP:"([A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5})" EXTRACT="$1"
SET !CLIPBOARD {{!EXTRACT}}

Follow up thread: viewtopic.php?f=7&t=30724&p=84271#p84271
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How do I structure a code to auto copy any text in a pattern XXXXX-XXXXX-XXXXX-XXXXX-XXXXX ?

Post by chivracq » Thu Dec 12, 2019 2:25 am

bb1000 wrote:
Wed Dec 11, 2019 5:53 pm
Final Script:

Code: Select all

VERSION BUILD=1005 RECORDER=CR
SET !ERRORIGNORE YES
SET !TIMEOUT 100000
SET !EXTRACT_TEST_POPUP NO
SEARCH SOURCE=REGEXP:"([A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5})" EXTRACT="$1"
SET !CLIPBOARD {{!EXTRACT}}
Follow up thread: viewtopic.php?f=7&t=30724&p=84271#p84271

Oh...!, good...!, Thanks for posting (again) your Script (even if I had to ask for that, ah-ah...! :wink: ), so that's the/a Solution for the 'REGEXP' using the 'SEARCH' Command. Alright, good-good...! :D

I would have some "Remarks"/Feedback about "the rest" of the Script as your '!TIMEOUT' Statement for example looks very strange to me :shock: , but OK, you started a Follow-up Thread directly even before I had a chance to see that Script and maybe react to it, but OK, fair enough, even if your "next" Thread is about Timeout Issues with this Script, and that it works "on some Pages" but not "on other Pages", so I'm not surprised, ah-ah...! Tja...! :twisted:

But OK, a bit late now for me, and Int. Co. was not working very well for me today..., I'll try to post in your other Thread tomorrow if I can..., but hum, I'll see, I might be a bit busy also, the "coming days", until after the WE probably..., (I'm a DJ IRL and I have one "big" Gig (to prepare) on Sa.... :wink: ), would have been "easier" (for me) if you had posted that Script directly in this current Thread, I then had the time and my Int. Co. was working when I replied earlier in your next Thread... But OK, never mind... :|
- (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...
bb1000
Posts: 17
Joined: Tue Dec 03, 2019 3:14 pm

Re: How do I structure a code to auto copy any text in a pattern XXXXX-XXXXX-XXXXX-XXXXX-XXXXX ?

Post by bb1000 » Thu Dec 12, 2019 2:39 am

The reason it didn’t work on other pages was because the source wasn’t there. That’s why I want it to timeout and then once it finds the regex it runs the script, that is why my timeout is so high, so it’s as if it’s monitoring the page until it’s found. Apologies for making another thread, just thought it was a different issue as this one was solved :wink: I really do appreciate your help, it really means a lot to me as I have no other help. I’m really struggling with this, I’ve been looking everywhere to find a way to timeout the search command, but can’t find anything. I would really appreciate if you could come back to this thread when you’re free.

Apart from that...Good luck with your gig!! :P

Thanks in advance.
Post Reply