Calculating string length in imacros - regex

These are the tags from where data is to be extracted
<div class="textForAType">
Agent
<span class="agentNameh">Vijay Realty</span>
</div>
Using the code "TAG POS=1 TYPE=span ATTR=CLASS:agentNameh&&TXT:* EXTRACT=TXT" gives the output Vijay Realty and TAG POS=1 TYPE=div ATTR=CLASS:textForAType&&TXT:* EXTRACT=TXT gives me O/P AgentAgent Vijay Realty
So I'm trying to replace the name "Vijay Realty" with blank in the output "AgentAgent Vijay Realty" and then count the number of characters and divide it by 2 so as to get the word "Agent"
So this happens to be the combined code
TAG POS=1 TYPE=span ATTR=CLASS:agentNameh&&TXT:* EXTRACT=TXT
SET AgentName {{!EXTRACT}}
TAG POS=1 TYPE=div ATTR=CLASS:textForAType&&TXT:* EXTRACT=TXT
SET Owner {{!EXTRACT}}
SET CertiAgent EVAL("var s=\"{{!Owner}}\"; s.replace(s.match(/{{!AgentName}}/gi),'');")
'PROMPT {{CertiAgent}}
SET !VAR1 EVAL("var x=\"{{!CertiAgent}}\"; x=x.match(/^.{(length(\"{{!CertiAgent}}\")/2)}/).join(''); x;")
PROMPT {{!VAR1}}
But running this code gives error
unterminated parenthetical, line: 8 (Error code: -1001)
I don't know what exactly the error is.
Any suggestion on where I.m making a mistake .
Thanks
P.s: I'm trying to extract the text after the attribute "textForAType"

Here you go... You need to remember to clear out the EXTRACT Variable, or otherwise each extraction you make will be appended to it (which is why you have "Agent" twice in the results).
The code below should resolve your issue and provide you with the value of "Agent"
TAG POS=1 TYPE=span ATTR=CLASS:agentNameh&&TXT:* EXTRACT=TXT
SET AgentName {{!EXTRACT}}
'display extracted value for testing purposes
PROMPT {{AgentName}}
'Clear the Internal Extract buffer
SET !EXTRACT NULL
TAG POS=1 TYPE=div ATTR=CLASS:textForAType&&TXT:* EXTRACT=TXT
SET Owner {{!EXTRACT}}
'display extracted value for testing purposes
PROMPT {{Owner}}
'Clear the Internal Extract buffer
SET !EXTRACT NULL
'Use Javascript evaluation to replace the "agentNameh" section of "textForAType" to (blank), and return results as CertiAgent2
SET CertiAgent2 EVAL("var x=\"{{Owner}}\"; x.replace(\"{{CertiAgent}}\",\"\");")
'display variable value for testing purposes
PROMPT {{CertiAgent2}}
If this answer helped, please mark as such.

Related

RegEx - Exclude random String between specific tags

I have to change a lot of tags in an XML-Document and think RegEx might be the best solution for this, but I can't figure out the correct snytax:
<tag1 attribute="value1">random content1<tag1>
<tag1 attribute="value2">random content2<tag1>
<tag1 attribute="value1">random content3<tag1>
This is the current state. "tag1" can have different values for "attribute" at the moment. The new structure gets rid of those combinations, but instead uses specific elements for that.
<tag1 attribute="value1">random content1<tag1>
<!-- tag1 + value1 requires <tag2>random content1</tag2> : -->
<tag2>random content1<tag2>
<tag1 attribute="value2">random content2<tag1>
<!-- tag1 + value2 requires <tag3>random content2</tag3> : -->
<tag3>random content1<tag3>
I need to change all of those tag->attribute-combinations without touching the content inbetween. Is it possible to select those specific tags while excluding their contents?
Help is very appreciated!

how could I solve this equation, any idea?

I have the code for imacros
I would like to receive the result.
TAG POS=1 TYPE=INPUT:HIDDEN ATTR=TYPE:text&&NAME:firstNumber&&VALUE:8
TAG POS=1 TYPE=INPUT:HIDDEN ATTR=TYPE:text&&NAME:secondNumber&&VALUE:9
SET !EXTRACT_TEST_POPUP NO
SET !EXTRACT NULL
TAG POS=1 TYPE=INPUT:HIDDEN ATTR=TYPE:text&&NAME:firstNumber&&VALUE:8 EXTRACT=TXT
SET !VAR1 {{!EXTRACT}}
SET !EXTRACT_TEST_POPUP NO
SET !EXTRACT NULL
TAG POS=1 TYPE=INPUT:HIDDEN ATTR=TYPE:text&&NAME:secondNumber&&VALUE:9 EXTRACT=TXT
SET !VAR2 {{!EXTRACT}}
SET !VAR3 EVAL("var a=\"{{!VAR1}}\"; var b=\"{{!VAR2}}\"; var z = (((a + b))); z")
PROMPT {{!VAR3}}
I already tried this code, and even result
click to see the result of imcros
any idea how I can solve.
All what you need is to parse the variable to int before plus action.
var a = parseInt( "{{!VAR1}}" );
var b = parseInt( "{{!VAR2}}" );
var z = a + b;
z;
So for your source code you just need to do:
TAG POS=1 TYPE=INPUT:HIDDEN ATTR=TYPE:text&&NAME:firstNumber&&VALUE:8
TAG POS=1 TYPE=INPUT:HIDDEN ATTR=TYPE:text&&NAME:secondNumber&&VALUE:9
SET !EXTRACT_TEST_POPUP NO
SET !EXTRACT NULL
TAG POS=1 TYPE=INPUT:HIDDEN ATTR=TYPE:text&&NAME:firstNumber&&VALUE:8 EXTRACT=TXT
SET !VAR1 {{!EXTRACT}}
SET !EXTRACT_TEST_POPUP NO
SET !EXTRACT NULL
TAG POS=1 TYPE=INPUT:HIDDEN ATTR=TYPE:text&&NAME:secondNumber&&VALUE:9 EXTRACT=TXT
SET !VAR2 {{!EXTRACT}}
SET !VAR3 EVAL("var a = parseInt( "{{!VAR1}}" );var b = parseInt( "{{!VAR2}}" );var z = a + b;z")
PROMPT {{!VAR3}}

Relative Positioning Text Extraction Failing

I'm trying to extract player values from hockey-resource from player pages, and I've hit a snag around pulling out the position and handedness of players as well as height and weight.
I can pull out the whole row but then it's formatted poorly and doesn't work for what I'll eventually do (loop through the player pages and save into the table next to the original name). Here's what I've got so far:
VERSION BUILD=9030808 RECORDER=FX
TAB T=1
URL GOTO=https://www.hockey-reference.com/players/d/duchema01.html
TAG POS=R1 TYPE=STRONG ATTR=TXT:Shoots EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=* FILE=nhlplayerrecord_duchema01.csv
this totally fails, although given the documentation it seems like that should be prime territory to work. Here's the bits that pull full row:
VERSION BUILD=9030808 RECORDER=FX
TAB T=1
URL GOTO=https://www.hockey-reference.com/players/d/duchema01.html
TAG POS=1 TYPE=P ATTR=TXT:* EXTRACT=TXT
TAG POS=2 TYPE=P ATTR=TXT:* EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=* FILE=nhlplayerrecord_duchema01.csv
Any advice on what I've missed or how I might better position this to find the values would be great.
using Firefox, mac OSX
thanks
In your first snippet you use relative positioning in your TAG POS=R1. Relative positioning requires a previous TAG command to find the next position, though, which you do not have. That's why your first snippet fails at that line.
<p>
<strong>Position</strong>: C •
<strong>Shoots</strong>: Left
</p>
If you only want the 'C' and the 'Left' in this specific example you could extract the entire P as you do in your second snippet and drop all the unneeded parts with an EVAL statement.
The following reads C and Left and writes them to the specified file, you can proceed similarly for height and weight.
VERSION BUILD=9030808 RECORDER=FX
TAB T=1
URL GOTO=https://www.hockey-reference.com/players/d/duchema01.html
TAG POS=1 TYPE=P ATTR=TXT:* EXTRACT=TXT
' Create an extract backup, it's overwritten to save data
SET extract_backup {{!EXTRACT}}
' Read and save Position
SET !EXTRACT EVAL("var pos='{{extract_backup}}'.split('•'); pos[0].split(':')[1].replace(/ /g,'');")
SAVEAS TYPE=EXTRACT FOLDER=* FILE=nhlplayerrecord_duchema01.csv
' Read and save Shoots
SET !EXTRACT EVAL("var shoots='{{extract_backup}}'.split('•'); shoots[2].split(':')[1].replace(/ /g,'');")
SAVEAS TYPE=EXTRACT FOLDER=* FILE=nhlplayerrecord_duchema01.csv

Make iMacro Check Frame F=1-8 until it finds a working one

So I've spent a few hours googling and trying to find a solution, but I failed. And I need to do this in an ,iim iMacro script, not .js script.
I have this iMacro:
VERSION BUILD=8920312 RECORDER=FX
SET !ERRORIGNORE YES
SET !TIMEOUT_PAGE 2
TAB T=1
REFRESH
WAIT SECONDS=10
FRAME F=1
TAG POS=1 TYPE=SPAN ATTR=TXT:follow
FRAME F=2
TAG POS=1 TYPE=SPAN ATTR=TXT:follow
FRAME F=3
TAG POS=1 TYPE=SPAN ATTR=TXT:follow
FRAME F=4
TAG POS=1 TYPE=SPAN ATTR=TXT:follow
FRAME F=5
TAG POS=1 TYPE=SPAN ATTR=TXT:follow
FRAME F=6
TAG POS=1 TYPE=SPAN ATTR=TXT:follow
FRAME F=7
TAG POS=1 TYPE=SPAN ATTR=TXT:follow
FRAME F=8
TAG POS=1 TYPE=SPAN ATTR=TXT:follow
WAIT SECONDS=3
Now, the problem is that the FRAME F=# is dynamic, and to make this code work fast I had to put the SET !TIMEOUT_PAGE 2 as well, otherwise the iMacro gets stuck for 5 seconds on each FRAME, making the iMacro very slow...
Is there a way to do something like:
SET !VAR1 EVAL("var letters = ['1','2','3','4','5','6','7','8']; var string = ''; for(var i = 0; i < 10; i++){string += letters[parseInt(Math.random() * 25)]}; string")
And then use: FRAME F={{!VAR1}} in every place needed???
I basically need the code to start checking for Frames, and check 1, then 2, then 3, etc until it finds the working one, and the second it does to move on.
I'm using the iMacros addon for Firefox.
Thank you

How do I get the name of a tag in TinyXML?

For example:
test.xml
<fruit taste="good">whatever</fruit>
How can I get the name-string of the tag "fruit" (which would be "fruit" of course) using TinyXML?
Use TiXmlElement::Value()
The Value function returns different things based on the type.
Document: filename of the xml file
Element: name of the element
Comment: the comment text
Unknown: the tag contents
Text: the text string