Sometimes when performing a scrape you need to perform an action once during the whole scrape such as login or carry out a search, with GrabzIt's Web Scraper this is easy. First of all create a new scrape with the normal details such as the starting page of the scrape and any other options.
Then go to the Scrape Instructions and enter the text below.
if (Global.get("myaction") != "done") { Global.set("myaction", "done"); //Put the action you only want to do once here }
The above code uses a global variable called myaction
to check if the action has been executed. If the global variable has not been set to done the action within the if statement is executed and the myaction
variable is set so it is not executed again.
When writing scrape instructions it is important to remember that the state of JavaScript variables in the scrape instructions is not kept when the scraper moves between webpages, unless you use the Global functions to save variables, as shown below.
Global.set("myvariable", "hello"); var myvar = Global.get("myvariable");
To create a persistent global variable pass true to the persist parameter in the Global.set method, as shown below.
Global.set("myvariable", "hello", true);