Как запланировать / повторить CheerioCrawler - PullRequest
0 голосов
/ 14 апреля 2020

Я попытался сделать это рекурсивным, заставить al oop вызывать одну и ту же функцию снова и снова, использовать «контроллер» для запуска основного скрипта.

Я использую Apify- sdk, никогда не использовал Apify и не может ничего найти в документации, даже если на странице мотивации написано:

Запланируйте периодический запуск кода и отправьте уведомление об ошибках. Blockquote



Apify.main(async () => {
    await getconfig.run()

    var crawlerConfig = require('./crawlerConfig.json')
    namesList = crawlerConfig.usernames
    goldammounts = crawlerConfig.goldammounts


    const requestList = new Apify.RequestList({
        sources
    });
    await requestList.initialize();





    const crawler = new Apify.CheerioCrawler({

        requestList,

        // The crawler downloads and processes the web pages in parallel, with a concurrency
        // automatically managed based on the available system memory and CPU (see AutoscaledPool class).
        // Here we define some hard limits for the concurrency.
        minConcurrency: 10,
        maxConcurrency: 50,

        // On error, retry each page at most once.
        maxRequestRetries: 1,

        // Increase the timeout for processing of each page.
        handlePageTimeoutSecs: 60,

        // This function will be called for each URL to crawl.
        // It accepts a single parameter, which is an object with the following fields:
        // - request: an instance of the Request class with information such as URL and HTTP method
        // - html: contains raw HTML of the page
        // - $: the cheerio object containing parsed HTML
        handlePageFunction: async ({ request, html, $ }) => {
            console.log(`Processing ${request.url}...`);

            // Extract data from the page using cheerio.



           //removed all the code because this is unecessary for the problem




            // Store the results to the default dataset. In local configuration,
            // the data will be stored as JSON files in ./apify_storage/datasets/default
            await Apify.pushData({

                url: request.url,
                quantity: goldamout,
                server: server,
                subserver: subserver,
                prices: prices
            });
        },

        // This function is called if the page processing failed more than maxRequestRetries+1 times.
        handleFailedRequestFunction: async ({ request }) => {
            console.log(`Request ${request.url} failed twice.`);
        },
    });


        await crawler.run();

        console.log('Crawler finished.');
        await uploadspreadsheet.run()

        //should repeate here



});

Я хочу, чтобы он полностью запустился или просто Cheerio crawler (ссылки не изменятся)

Спасибо:)

...