Getting function Expected when tyring to use reverse()

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.
Forum rules
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
chivracq
Posts: 8406
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Getting function Expected when tyring to use reverse()

Post by chivracq » Thu Jun 29, 2017 5:04 am

azbob wrote:I get these errors when I run the new code:

Code: Select all

Error -1250: JScript statement in EVAL contains the following error: Function expected. Line 8: SET Name1 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split('<br>'); y=x[0].split('>'); z=y[1].trim(); z;")
Error -1250: JScript statement in EVAL contains the following error: Function expected. Line 9: SET Name2 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split('>'); y=x[1].split('<'); z=y[0].trim(); z;")
azbob wrote:Let me qualify that I got those errors when I ran it in Imacros Browser.
When I run in firefox it works, How come??

Code: Select all

Name1: ___undefined___
Name2: _JOHN R GRAY II_
Address: _4965 E Red Range Way   CAVE CREEK,AZ 85331
Oh...!, so I was right about 'Name2', ah-ah...!

Pfff, dunno actually, I've never used the iMacros Browser (iMB), so I can only test on FF (or I actually use Pale Moon rather than FF), and so I only know how FF will (or is supposed to) behave... No idea why it doesn't work in iMB actually... But hum..., maybe your original Script with 'reverse()' was actually correct and might work in FF then...
But hum, the "Function expected" Errors might come from 'trim()' which I guess is not a "Standard" JS Function, I normally use this Site for JS Documentation and it's not even listed...!:
https://www.tutorialspoint.com/javascri ... object.htm
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
azbob
Posts: 76
Joined: Mon Sep 21, 2009 6:16 pm

Re: Getting function Expected when tyring to use reverse()

Post by azbob » Thu Jun 29, 2017 6:22 am

Well Thanks to you I got it working,I wish there was a more 'solid' delimiter between house address and city than double spaces, but I'll take it.

Code: Select all

TAG POS=2 TYPE=TD ATTR=CLASS:ReportManagerTable_rows EXTRACT=HTM      
'SET Name1 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split('<br>'); y=x[0].split('>'); z=y[1].trim(); z;")
SET Name2 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split('>'); y=x[1].split('<'); z=y[0].trim(); z;")
SET Address EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split('<br>'); y=x[1].split('<img'); z=y[0].trim(); z;")
SET House EVAL("var s='{{Address}}'; var x,y,z; x=s.split('  '); x[0];")
SET Zip EVAL("var s='{{Address}}'; var x,y,z; x=s.split(','); y=x[1].split(' '); y[1];")
SET City EVAL("var s='{{Address}}'; x=s.split('  '); y=x[1].split(','); y[0];")
PROMPT EXTRACT:<SP>_{{!EXTRACT}}_<BR>Name2:<SP>_{{Name2}}_<BR>Address:<SP>_{{Address}}_<BR>House:<SP>_{{House}}_<BR>City:<SP>_{{City}}_<BR>zip:<SP>_{{Zip}}_
PROMPT Results:

Code: Select all

EXTRACT: _<td class="ReportManagerTable_rows" style="outline: 1px solid blue;">       JOHN R GRAY II
4965 E Red Range Way   CAVE CREEK,AZ 85331<img src="/images/spacer1.gif" width="1" height="1" border="0">      </td>_
Name2: _JOHN R GRAY II_
Address: _4965 E Red Range Way   CAVE CREEK,AZ 85331_
House: _4965 E Red Range Way_
City: _ CAVE CREEK_
zip: _85331_
BTW: I noticed that when i did this results came back "undefined".

Code: Select all

SET House EVAL("var x,y,z; s='{{Address}}';  x=s.split('  '); x[0];")
Yet this syntax works:

Code: Select all

SET House EVAL("var s='{{Address}}'; var x,y,z; x=s.split('  '); x[0];")
What is the explanation for that??

Again thanks for all your help!
chivracq
Posts: 8406
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Getting function Expected when tyring to use reverse()

Post by chivracq » Thu Jun 29, 2017 2:52 pm

azbob wrote:Well Thanks to you I got it working,I wish there was a more 'solid' delimiter between house address and city than double spaces, but I'll take it.

Code: Select all

TAG POS=2 TYPE=TD ATTR=CLASS:ReportManagerTable_rows EXTRACT=HTM      
'SET Name1 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split('<br>'); y=x[0].split('>'); z=y[1].trim(); z;")
SET Name2 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split('>'); y=x[1].split('<'); z=y[0].trim(); z;")
SET Address EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.split('<br>'); y=x[1].split('<img'); z=y[0].trim(); z;")
SET House EVAL("var s='{{Address}}'; var x,y,z; x=s.split('  '); x[0];")
SET Zip EVAL("var s='{{Address}}'; var x,y,z; x=s.split(','); y=x[1].split(' '); y[1];")
SET City EVAL("var s='{{Address}}'; x=s.split('  '); y=x[1].split(','); y[0];")
PROMPT EXTRACT:<SP>_{{!EXTRACT}}_<BR>Name2:<SP>_{{Name2}}_<BR>Address:<SP>_{{Address}}_<BR>House:<SP>_{{House}}_<BR>City:<SP>_{{City}}_<BR>zip:<SP>_{{Zip}}_
PROMPT Results:

Code: Select all

EXTRACT: _<td class="ReportManagerTable_rows" style="outline: 1px solid blue;">       JOHN R GRAY II
4965 E Red Range Way   CAVE CREEK,AZ 85331<img src="/images/spacer1.gif" width="1" height="1" border="0">      </td>_
Name2: _JOHN R GRAY II_
Address: _4965 E Red Range Way   CAVE CREEK,AZ 85331_
House: _4965 E Red Range Way_
City: _ CAVE CREEK_
zip: _85331_
BTW: I noticed that when i did this results came back "undefined".

Code: Select all

SET House EVAL("var x,y,z; s='{{Address}}';  x=s.split('  '); x[0];")
Yet this syntax works:

Code: Select all

SET House EVAL("var s='{{Address}}'; var x,y,z; x=s.split('  '); x[0];")
What is the explanation for that??

Again thanks for all your help!
Good-good-good...! Much simpler than your original "cumbersome" 'EVAL()' Statements, you see... :wink:

"I wish there was a more 'solid' delimiter between house address and city than double spaces..."
=> Well, don't complain, you have 3 Spaces in a row, more "unpredictable" maybe in some cases would be if there was only 1 Space...

Well, about the "__undefined__" for 'House', hum, dunno, both Statements return the same (correct) Result for me (on v8.8.2 for FF), and both with 2 or 3 Spaces in the 'split()'...
I notice you have a Double Space in the first Statement, before the "x=...", maybe iMB is sensitive for those...

Stg interesting I noticed is that you indeed don't even need the "var x,y,z;" Declaration like you removed/forgot(...?) in 'City', and you even don't need the "var " part each time if the Var you want to declare/use is defined with a "=", so this one works as well:

Code: Select all

SET City EVAL("s='{{Address}}'; x=s.split('  '); y=x[1].split(','); y[0];")
=> ... which would allow you to simplify further all your Statements...

I had already noticed it some time ago, but I never really checked "correctly"..., and that's interesting for myself as well, as I often use 'EVAL()' Statements where I reuse quite a few previous Vars + usually a few Temp "x,y,z" Vars, that will shorten my own 'EVAL()' Statements each time by about 20 Chars, ah-ah...! :D
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Post Reply