Refresh Page Variable On Click


#1

I am clicking on an element on the page and want to get the updated variable values on the page.

function pageFunction(context) {
	// called on every page the crawler visits, use it to extract data from it
	var $ = context.jQuery;
	var result = [];
    var nextButton = $('#button-sock');
    console.log(data);
    nextButton.click();
    console.log('After Click next button');
    setTimeout(function(){}, 1000); 
    // in the browser the data variable changes value but not in crawler
    console.log(data);

#2

Hi @Barry_Schneider,

I guess this code comes from Apify crawler.
If so, you have to use callback there. You need to call context. willFinishLater() and than you have to call context.finish() in callback of setTimeout function:

function pageFunction(context) {
	// called on every page the crawler visits, use it to extract data from it
	var $ = context.jQuery;
	var result = [];
    var nextButton = $('#button-sock');
    console.log(data);
    nextButton.click();
    console.log('After Click next button');
    constext.willFinishLater();
    setTimeout(function(){
     // in the browser the data variable changes value but not in crawler
    console.log(data);
    constext.finish();
   }, 1000); 
  ...
}

Let me know if it helps.