Attempt to invoke method: get() on undefined variable or class name:
Thought I would find lots of examples on why this error ocure but coult not get any hints in the archive. I'm trying to build a memory efficient Next page method using:
if (dataRecord.get("NEXT_URL")!=null);
{
url = "";
url =+ "http://www.thehost.com/";
url =+ session.getVariable("NEXT_URL");
maxPage = Integer.parseInt(dataRecord.get("MAX_PAGE"));
for (i=2; i
session.setVariable("URL", url);
session.setVariable("NEXT_PAGE", i);
session.log("Starting page " + i + " of " + maxPage);
session.scrapeFile("Search results");
}
}
else
{
session.log("+++No further pages detected");
}
But I don't get any further than the first line when this appears: The error message was: Attempt to invoke method: get() on undefined variable or class name: dataRecord : at Line: 1.
And it beats me....
/Johan
variable scope
Johan,
Hello. The error you're getting is likely due to the NEXT_URL variable being out of scope. If you'll take a look at the following, you'll see that the dataRecord is only in scope when your script is being called "After each pattern application".
http://community.screen-scraper.com/scraping_engine/using_scripts#scope
My guess is, you're calling your script "After pattern is applied". If so, the current dataRecord in your dataSet (NEXT_URL) is out of scope.
My next guess is that your NEXT_URL extractor pattern matches more than one time and therefore you don't want to call your script after each pattern application because that would cause the next page link to be clicked twice. This is a common problem. The solution is to find additional HTML surrounding your NEXT_URL token that makes it different from the other next link on the page.
If the next link at the top of the search results has something unique about it that is closer to your token, then use it. screen-scraper applies the extractor patterns to the entire HTML each time so it doesn't matter if your matching for HTML at the top of the page when your NEXT_URL extractor pattern is the last one in the sequence.
Hope this helps,
-Scott
Your guesswork is
Your guesswork is head-on-target Scott. DataRecord out of scope was the problem.
Thanks!
Johan