Using variables for identifiers in TAG command

Discussions and Tech Support specific to the iMacros for Chrome extension.
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
Post Reply
regstuff
Posts: 6
Joined: Sun Jun 17, 2018 10:52 am

Using variables for identifiers in TAG command

Post by regstuff » Sun Jun 17, 2018 11:12 am

VERSION BUILD=1002
Chrome: Version 61.0.3163.100 (Official Build) (64-bit)
Windows 10

Hi,

I've created a macro to scrape an element from a certain page, and then store that data in a variable, and use that variable to determine what link to click on another page.

Like so:

Code: Select all

'Extract the data and store it
TAG POS=1 TYPE=DIV ATTR=CLASS:del EXTRACT=TXT
SET !VAR2 {{!EXTRACT}}
'Use the stored data to choose another link
TAG POS=1 TYPE=A ATTR=TXT:{{!VAR2}}
The variable is picking up the data fine, and if instead of using the variable, I insert the actual data itself, the code runs fine. The uses wildcards, and so !VAR2 is in the format *WEBSITENAME*

But I get this error: RuntimeError: element A specified by TXT:{{!VAR2}} was not found, line: 12
Which is strange because the element is actually there on the page, and as I said, if I change the code to use the data itself, instead of a variable, it works fine.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Using variables for identifiers in TAG command

Post by chivracq » Sun Jun 17, 2018 12:45 pm

regstuff wrote:

Code: Select all

VERSION BUILD=1002
Chrome: Version 61.0.3163.100 (Official Build) (64-bit)
Windows 10
Hi,

I've created a macro to scrape an element from a certain page, and then store that data in a variable, and use that variable to determine what link to click on another page.

Like so:

Code: Select all

'Extract the data and store it
TAG POS=1 TYPE=DIV ATTR=CLASS:del EXTRACT=TXT
SET !VAR2 {{!EXTRACT}}
'Use the stored data to choose another link
TAG POS=1 TYPE=A ATTR=TXT:{{!VAR2}}
The variable is picking up the data fine, and if instead of using the variable, I insert the actual data itself, the code runs fine. The uses wildcards, and so !VAR2 is in the format *WEBSITENAME*

But I get this error: RuntimeError: element A specified by TXT:{{!VAR2}} was not found, line: 12
Which is strange because the element is actually there on the page, and as I said, if I change the code to use the data itself, instead of a variable, it works fine.
No need to open Duplicates, I guess you'll have understood... :wink:
And I'm not sure your Thread will be specific to the 'iMacros for CR' Sub-Forum..., unless your Script works fine in some other Browser but only fails on CR..., which you then should have mentioned...
But OK, good Quality anyway... (Some Word is missing in "The [Site?] uses wildcards,"...)

OK, if I understand correctly, you literally get "TXT:{{!VAR2}}" in the RuntimeError, and '{{!VAR2}}' doesn't get converted to the Value/Content it should use..., possibly related to the 2 outer Wildcards around the Site Name... You didn't post the URL, then I cannot have a look myself...

- You don't really need to use an extra Temp Var ('!VAR2'), you could use "ATTR=TXT:{{!EXTRACT}}" directly, as you only do one Extract and you don't do any Manipulation on the Content of the Extract... (even if that shouldn't play a role...)

- You should make sure that the '!EXTRACT' is "clean" and doesn't contain any Spaces and/or Soft Returns (that you would then need to 'trim()' using 'EVAL()'). You can check that with a simple 'PROMPT':

Code: Select all

PROMPT EXTRACT:<SP>_{{!EXTRACT}}_<BR>VAR2:<SP>_{{!VAR2}}_
The Underscores around the 2 Vars are meant to display any Spaces/Soft Returns.

- I actually used recently a Wildcard inside a Var to reuse that Var for a 'TAG' 'ATTR' like you do, and I wasn't sure it would work correctly..., but it does..., but "my" Wildcard is in the middle or the Var and not at the beginning + end like in your case. (And I use a different Browser and therefore a different iMacros "Flavour"...)

- If the Pb is those 2 Wildcards, you might need to remove them from the '!EXTRACT' using 'EVAL()'..., and you'll need to add them again in the 'TAG' Statement, but outside the '{{!VAR2}}' and they then will be treated like "real" Wildcards by iMacros...
This should do the Trick, I would think...:

Code: Select all

'Extract the data and store it
TAG POS=1 TYPE=DIV ATTR=CLASS:del EXTRACT=TXT
SET !VAR2 EVAL("var s='{{!EXTRACT}}'; var z=s.split('*'); z[1];")
PROMPT EXTRACT:<SP>_{{!EXTRACT}}_<BR>VAR2:<SP>_{{!VAR2}}_
'Use the stored data to choose another link
TAG POS=1 TYPE=A ATTR=TXT:*{{!VAR2}}*
(Not tested...)
- (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...
regstuff
Posts: 6
Joined: Sun Jun 17, 2018 10:52 am

Re: Using variables for identifiers in TAG command

Post by regstuff » Mon Jun 18, 2018 5:09 am

Thanks for the reply, and I'd like to apologize for wasting your time because I was making a stupid mistake. I was actually extracting something before coming to this part of the macro. And I forgot to set Extract to Null. So I was getting an appended Extract in effect.

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

Re: Using variables for identifiers in TAG command

Post by chivracq » Mon Jun 18, 2018 10:12 am

regstuff wrote:Thanks for the reply, and I'd like to apologize for wasting your time because I was making a stupid mistake. I was actually extracting something before coming to this part of the macro. And I forgot to set Extract to Null. So I was getting an appended Extract in effect.

Thanks and sorry again!
Ah-ah...!, I did mention stg like "you only do ONE Extract" ah-ah...! :twisted:

But "funnily" enough, the Code I posted should still work in your Case (even without the "SET !EXTRACT NULL", ah-ah...!), unless your previous Extract(s) also contained some "*' (Wildcard(s)), then you would need to adapt the "z[1]" to "z[3]" or "z[5]" or whatever but I had thought of that Eventuality, ah-ah...! :wink:

OK, no need to apologize, I'm happy you realized and understood by yourself what was the Cause of your Code not working correctly... :D
I think the 'PROMPT' must have helped you as well realizing that you had 2 or more Extracts in the '!EXTRACT' Var... :idea:
=> The 'PROMPT' is always your best Friend to debug your Script, ah-ah...!! :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...
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Using variables for identifiers in TAG command

Post by chivracq » Sun Jul 08, 2018 6:47 am

[Not related with current Thread...]

=> What is "bothering" you, @regstuff...? (I've seen you quite a few times Online and checking the Forum since 36 hours, ah-ah...!)
=> Open a New Thread (in the correct Sub-Forum, and mention your FCI), and simply ask your Qt... :idea: , there are no stupid Qt's... :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...
Post Reply