how could I solve this equation, any idea? - imacros

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}}

Related

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

Calculating string length in imacros

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.

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

Excel Print command, creating text template

Hi I am new to VBA and was looking to output my Excel sheet data into a text template. So far all I have been able to do is output the data but I don't know where to go from there. What I have:
Private Sub CommandButton1_Click()
Dim myFile As String, rng As Range, cellValue As Variant, i As Integer, j As Integer
myFile = "C:\Users\Francis\Desktop\redirect.txt"
Set rng = Selection
Open myFile For Output As #1
For i = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
cellValue = rng.Cells(i, j).Value
If j = rng.Columns.Count Then
Print #1, cellValue
Else
Print #1, cellValue,
End If
Next j
Next i
Close #1
End Sub
I wish to change this so the text output isn't just "celldataA*" "celldataB*" etc.
I want to make it so that the document starts with
<rule> and ends with </rule>
Then each row would come out as
<rule name="Rule rownumber*" patternSyntax="ExactMatch" stopProcessing="true">
<match url="celldataA*" />
<action type="Redirect" url="celldataB*" />
</rule>
Any pointers? It's that or I manually do it myself 3.5k times so any help at all is welcome.
These resources on generating XML from Excel should help you.
MS Office.Com: Create an XML data file and XML schema file from worksheet data
MSDN Library: Creating an XML Mapping Schema in Excel 2010
Mr Excel: Using XML in Excel 2003
essentially you create a schema file then output the xml data using that schema to define the data.

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