2

I have a following trouble in APIFY. I would like to write a function that saves HTML body of a current page and then click to the next page, saves HTML body etc.

I tried this:

var result = []; 
    var scrapeAndClick = function() {   
        $("div.ui-paginator.ui-paginator-top.ui-widget-header.ui-corner-top").each(function() {

                result.push(
                $(this).html()               
                );


            //klikej na dalsi stranky

            var nextButton = $('a.ui-paginator-next.ui-state-default.ui-corner-all');

            console.log('Click next button');
            nextButton.click().delay(4000)


            });    

    };


    scrapeAndClick();

In Google Chrome console it returns me only the HTML body of the first page. APIFY does not return anything.

Can someone see, where is the problem?

If is someone interested in the whole Page function:

async function pageFunction(context) {
    const {  log } = context;

    const searchSelector = 'div.ui-panel-content.ui-widget-content > button';

    //vyber "Gemeenschappelijk Landbouw Beleid" z Kies subsidie: 
    const subsidySelector = $("span.column2 > select.jsTruncate").val("10000");
    log.info('Select CAP ')
    subsidySelector    

    //klikni na Zoek
    log.info('Click search.')
    $(searchSelector).eq(0).click()



    //loopujeme dalsi stranky a ukladame html body



    var result = []; 
    var scrapeAndClick = function() {   
        $("div.ui-paginator.ui-paginator-top.ui-widget-header.ui-corner-top").each(function() {

                result.push(
                $(this).html()               
                );


            //klikej na dalsi stranky

            var nextButton = $('a.ui-paginator-next.ui-state-default.ui-corner-all');

            console.log('Click next button');
            nextButton.click().delay(4000)


            });    

    };


    scrapeAndClick();



    return result;
} 

StartURL is this: https://mijn.rvo.nl/europese-subsidies-2017

I found an old question on APIFY forum (https://forum.apify.com/t/clickable-link-that-doesnt-change-the-url/361/3), however it seems that it was done on old version of APIFY crawler.

Thanks a lot for any help!

jan novotný
  • 118
  • 1
  • 8

0 Answers0