Relative Positioning Text Extraction Failing - imacros

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

Related

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

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

Find level in navigation structure?

I have a sitecore 6 solution where the body background image changes depending on wich level you are currently on;
Home
- Subpage 1
-- Sub-subpage 1
-- Sub-subpage 2
--- Sub sub subpage 1
- Subpage 2
-- Sub-subpage 1
So i have a bg image for "Home", a bg image for "Subpage 1" and "Subpage 2" and a bg image for "Sub-subpage 1, 2" etc.
How would i check for the level in xslt?
It's kinda hard to say, as I'm not quite sure I've understood the question fully.
But one way would be to use:
<xsl:value-of select="count(ancestor::*)"/>
or
<xsl:value-of select="count(ancestor::node())"/>
See this page for an explanation of the difference:
http://www.dpawson.co.uk/xsl/sect2/N2193.html

cfchart ignores my scalefrom value

I have the following codes in my page.
The style variable holds the custom style.
<cfchart chartheight="450" chartwidth="550" gridlines="9" yaxistitle="Score" scalefrom="20" scaleto="100" style="#style#" format="png" >
<cfchartseries query="variables.chart_query" type="scatter" seriescolor="##000000" itemcolumn="MyItem" valuecolumn="MyScore"/>
</cfchart>
Before I begin, please see chart_good.jpg. This is how I want my report to come up. On the x-axis, there will always be three items as long as at least one of them has values. If an item does not have any values (i.e. 2010), there would not be a marker in the chart.
The problem occurs only when only one item has value. Please see chart_bad.jpg. As you can see, 2008 and 2010 do not have any values; y-axis is now scaled from 0 to 100. I have tried setting one of the items (ex. 2008) a value of 0 or something off the chart; it would scale according to this off-the-chart value and the 2009 value. In short, I have to have at least two items with values between 20 and 100 in order for cfchart to scale from 20 to 100.
My question is, how can I correct the issue so that cfchart would ALWAYS scale from 20 to 100? I am running CF9.
What is inside your style variable?
I would suggest not using scaleFrom="" and scaleTo="" in the cfchart tag as they can be buggy sometimes. I believe that Coldfusion's cfchart tag attempts to scale the chart automatically to what it deems the best fit. Instead I would build the chart's minimum and maximum scales inside a frameChart tag.
Example of a style variable to build a chart
<cfsavecontent variable="style">
<?xml version="1.0" encoding="UTF-8"?>
<frameChart is3D="false" font="Arial-11-bold">
<frame xDepth="0" yDepth="0" outline="black" lightColor="#CCCCCC" darkColor="#CCCCCC"
wallColor="#CCCCCC" frameSize="5" dashSize="3" gridColor="#333333">
<background type="HorizontalGradient" maxColor="#828EB0"/>
</frame>
<!--- THE BREAD AND BUTTER
NOTE: if you use variables for the scaleMin and scaleMax
make sure to surround them with a cfoutput tag
--->
<yAxis scaleMin="20" scaleMax="100">
<!--- --------------------- --->
<labelFormat style="Currency" pattern="#,##0"/>
<parseFormat pattern="#,##0"/>
<titleStyle></titleStyle>
</yAxis>
<legend allowSpan="true" isVisible="false" placement="Bottom" valign="Bottom" foreground="black"
isMultiline="true">
<decoration style="None"/>
</legend>
<elements outline="black" shapeSize="40"/>
<popup background="#748BA6" foreground="white"/>
<paint palette="Modern" paint="Plain" isVertical="true"/>
<insets right="5"/>
</frameChart>
</cfsavecontent>
Then all you have to do is load the variable into the style attribute like you already mentioned.
<cfchart format="png" chartWidth="550" chartHeight="175" style="#style#">
Also a great resource to use, is the Webcharts program that will be in your C:/coldfusion/charting/ directory. Just open webcharts.bat, create your custom chart, copy the xml code into your style variable, and voila!
Make sure to remove the scaleTo= and scaleFrom= from your cfchart tag if you decide to go this route.