Errors: conditional operators in interpreted java

Hello again, I've been running into what may be a simple and stupid error on my part in my most recent scraping.

I have 3 different session variables: low, high, and max, all of which need to be passed in the URL for my scrapings. I am attempting to write a portion of my script so that when my 'high' var exceeds the 'max' var (I increase low and high by 50 every time I scrape the page again) that the 'high' var will instead be assigned the same value of 'max'.

This is what I have so far in interpreted java:

session.addToVariable( "low", 50 );
session.addToVariable( "high", 50 );
if (session.getVariable( "high" ) > session.getVariable( "max" ) )
{
session.setVariable( "high", session.getVariable( "max" ) );
}

and Im not sure what Im doing wrong but I keep getting this error when I run my session: "Omega1: An error occurred while processing the script: P Omega scrape again
Omega1: The error message was: Operator: '">"' inappropriate for objects : at Line: 5."

Is there a proper way to get this syntax to test in the if statement if 'high' is larger than 'max'? Im really not sure what I'm doing wrong here. I realize that the way I am trying to set the variable might be wrong too, but the script never gets that far so I havent been able to fool around with it yet. I'm sure there is a simple misunderstanding of the syntax by me here holding me up but it's incredibly frustrating.

Errors: conditional operators in interpreted java

jeffreydean1,

I agree the error message is not the best. What it's trying to tell you, though, is that it can't convert a letter into an integer. If your "cat" variable is never going to be a number then you should not attempt to convert it into an integer. Just assign it to a local variable normally or simply reference it as the session variable.

-Scott

Errors: conditional operators in interpreted java

I was actually wondering if I had to declare them as integers because I had thought they were stored as strings, this (your above code) seems to work for a while on my scrape, but after a few scrapes and variable changes [color=red]I receive this error message and the scraping session terminates:

"Omega0: The error message was: Error in method invocation: Static method parseInt( java.lang.Integer ) not found in class'java.lang.Integer' : at Line: 4."
[/color]
I find it odd that I would receive this error when the exact same script was used quite a few times unaltered in the same session as the one where this error was thrown.

In my script, I scrape up to a max number of entries starting with a certain letter, 50 entries at a time, hence 'low' and 'high' as that is how the page is structured. Once I reach the 'max', I reset 'low' to 0 and 'high' to 50. I then change a 'cat' (category) variable to start scraping the entries starting with the letter 'B'. This is all shown in in my script below:

session.addToVariable( "low", 50 );
session.addToVariable( "high", 50 );

highVar = Integer.parseInt(session.getVariable( "high" ));
lowVar = Integer.parseInt(session.getVariable( "low" ));
maxVar = Integer.parseInt(session.getVariable( "max" ));
catVar = Integer.parseInt(session.getVariable( "cat" ));

if ( highVar >  maxVar )
{
   session.setVariable( "high", session.getVariable( "max" ) );
}

if (lowVar > maxVar )
{
   session.setVariable( "low", 0);
   session.setVariable( "high", 50);

// catVar of 4 is the letter 'A', catVar of 13 is 'B', etc...

        if (catVar == 4) {
          session.setVariable( "cat", 13);
          session.scrapeFile( "Omega0" );
                }

        if (catVar == 13) {
          session.setVariable( "cat", 12);
          session.scrapeFile( "Omega0" );
                }
        if (catVar == 12) {
          session.setVariable( "cat", 19);
          session.scrapeFile( "Omega0" );
                }
(...etc, snipped for length...)
}

if &#40; &#40;dataSet.getNumDataRecords&#40;&#41; > 0&#41; && &#40;lowVar < maxVar&#41;&#41;
&#123;
  session.scrapeFile&#40; "Omega1" &#41;;
&#125;

Now this script runs fine until after the flip back of 'low' to 0 and the change to 'cat' 13. After this changeover, the program WILL scrape Omega0, but after it does, is when I receive the error: "Omega0: The error message was: Error in method invocation: Static method parseInt( java.lang.Integer ) not found in class'java.lang.Integer' : at Line: 4."

Sorry to keep bothering you with these problems but I cannot fathom why screen scraper would suddenly think that this method is no longer found in the java.lang.Integer class.

Errors: conditional operators in interpreted java

jeffreydean1,

A thousand pardons. I steered you in the wrong direction. In order to evaluate the variables like you are you'll need to properly declare their type. In order to compare the two values like you are you first need to convert them to an integer using Integer.parseInt.

highVar = Integer.parseInt&#40;session.getVariable&#40; "high" &#41;&#41;;
maxVar = Integer.parseInt&#40;session.getVariable&#40; "max" &#41;&#41;;

if &#40; highVar >  maxVar &#41;
&#123;
        session.setVariable&#40; "high", session.getVariable&#40; "max" &#41; &#41;;
&#125;

Try that out...and sorry for the sending you on a detour.

-Scott

Errors: conditional operators in interpreted java

The 'max' session variable is declared and set in the script I use to start the scrape like so:

// Set the session variables.
runnableScrapingSession.setVariable( "low", "800" );
runnableScrapingSession.setVariable( "high", "850" );
runnableScrapingSession.setVariable( "max", "888" );

However, unlike the low and high variables, the max variable is reset by an extractor pattern after the first scrape to match what is found in the document (the 888 value is just a placeholder for testing purposes and could really be any number as long as it's higher than the 'high' variable)

I double-clicked the ~@max@~ in the extractor pattern and made sure it's being saved as a session variable, so something found in that extractor pattern should overwrite the original value of 888 correct?

I just tried your re-worked version of my code and it still throws the same error: "The error message was: Operator: '">"' inappropriate for objects : at Line: 18"

Im not sure if this would cause a problem, but the extractor pattern for the max variable matches twice (always an equal value) in each extraction so the log will show this:

"Omega1: Extracting data for pattern "null"
Omega1: The following data elements were found:
null--DataRecord 0:
max=888
Storing this value in a session variable.
Omega1: Processing scripts after a pattern application.
null--DataRecord 1:
max=888
Storing this value in a session variable."

Would this cause some kind of problem? I havent been able to find a pattern that simply captures the value a single time.

This really is baffling me, but it's good to know that my syntax was correct and I didnt overlook something basic.

Errors: conditional operators in interpreted java

jeffreydean1,

I'm not exactly sure why you're having that problem. I did a test where I set the values for the three variables in a script then call you sample code from another script without any error.

The issue must be related to how you're setting the value of the max variable. Try setting both the high and the max variables to local variables before evaluating them.

session.addToVariable&#40; "low", 50 &#41;;
session.addToVariable&#40; "high", 50 &#41;;

highVar = session.getVariable&#40; "high" &#41;;
maxVar = session.getVariable&#40; "max" &#41;;

if &#40; highVar >  maxVar &#41;
&#123;
session.setVariable&#40; "high", session.getVariable&#40; "max" &#41; &#41;;
&#125;

Hope this helps.

-Scott