Next page example error?

I'm trying to using this example script: http://community.screen-scraper.com/script_repository/Next_Page

but keep getting the error: The error message was: Unary operation "++" inappropriate for object : at Line: 16.

Line 16 contains:
// Increment the page number
currentPage++;

Ideas?

/Johan

Juuust about there.

I had to munge together the code a bit. For some reason, I need to stage the "int..." portion after the original "currentpage" line for it to work. Like this:

if (session.getVariable("NEXT") != null)
{
// Retrieve the page number of the page just scraped
currentPage = session.getVariable("PAGE");
if (currentPage == null)
currentPage = 1;
else
currentPage = Integer.parseInt(currentPage).toString();
int currentPage = Integer.parseInt(session.getVariable("PAGE"));

// write out the page number of the page just scraped
session.log("Last page was: " + currentPage);

// Increment the page number
currentPage++;

// write out the page number of the next page to be scraped
session.log("Next page is: " + currentPage);

// Set the "PAGE" variable with the incremented page number
session.setVariable("PAGE", currentPage);

// Clear the "NEXT" variable so that the next page is allowed to find it's own value for "NEXT"
session.setVariable("NEXT", null);

// Scrape the next page
session.scrapeFile("Nabber");
}

DON'T FORGET TO SET THE PAGE VARIABLE TO "SYSTEM". You remember how to do that, right? Double-click it (the "~@NEXT@~") in the second extractor pattern you're trying to match, and pickbox the "Save in Session Variable?". Or as the Regular expression if your html you're scraping is being cooperative. Mine isn't.

My problem now is calling the scraper again (my function "Nabber"). It's reinitializing my "init" file which contains my setups, so I can see the script figuring out "page 2", which promptly gets clobbered back to "page 1" by my init script. Must be something simple I'm missing...

Save some work

You could save some work. Instead of parsing your number to an integer, and incrementing it, you could just use session.addToVariable() and it will handle all of that.

http://community.screen-scraper.com/API/addToVariable

Ditto on that error...

Just tried the same code snippet (using the 4.5 basic), and I'm getting the same bug. Nothing I'm trying seems to get it past that point.

Oooo - I'm so close I can almost taste it.

Well, off to try another tack. Or method. Or maybe I'll just go eat some cake.

Screen-scraper has a method

Screen-scraper has a method that will increment a number, be it in the form of string, int, or integer. You just need to have it set as a session variable (which you likely do).

http://community.screen-scraper.com/API/addToVariable

One of the horrible "gotcha"s

One of the horrible "gotcha"s of Java is the way it tries to preserve "primitive" variables (int, float,... etc), yet insists that everything be an Object (Integer, Float... etc)

Annoyingly, the superior object "Integer" should be more powerful, but it is frequently inferior to the primitive "int". While "int" doesn't have any methods built into itself, it's the only thing that supports "++". You can't do this on an Integer.

If you're not doing anything with Integers to your knowledge, then maybe currentPage is actually a String at that spot? Lines 7 through 10 of that script try to turn it into a primitive "int" so as to avoid this trouble.

(note that the Integer.parseInt method on line 10 returns an "int" primitive, which is what you want.)